harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r512330 - in /harmony/enhanced/drlvm/trunk/vm/gc_cc/src: collect_slide_compact.cpp gc_for_vm.cpp gc_types.h init.cpp slot.cpp slot.h
Date Tue, 27 Feb 2007 17:27:58 GMT
Author: gshimansky
Date: Tue Feb 27 09:27:57 2007
New Revision: 512330

URL: http://svn.apache.org/viewvc?view=rev&rev=512330
Log:
Applied HARMONY-3218 [drlvm][winx64] gc_v41 fix

Tests passed on Ubuntu6 x86, Windows 2003 server x86_64 and SuSE9 x86_64.
On windows x86_64 build works, interpreter passes simple tests which require GC.


Modified:
    harmony/enhanced/drlvm/trunk/vm/gc_cc/src/collect_slide_compact.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_cc/src/gc_for_vm.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_cc/src/gc_types.h
    harmony/enhanced/drlvm/trunk/vm/gc_cc/src/init.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_cc/src/slot.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_cc/src/slot.h

Modified: harmony/enhanced/drlvm/trunk/vm/gc_cc/src/collect_slide_compact.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_cc/src/collect_slide_compact.cpp?view=diff&rev=512330&r1=512329&r2=512330
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_cc/src/collect_slide_compact.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_cc/src/collect_slide_compact.cpp Tue Feb 27 09:27:57
2007
@@ -30,7 +30,7 @@
 #include "slide_compact.h"
 
 unsigned char *mark_bits;
-int mark_bits_size;
+size_t mark_bits_size;
 fast_list<Partial_Reveal_Object*, 65536> objects;
 reference_vector references_to_enqueue;
 
@@ -232,7 +232,7 @@
     if (pinned_areas.size() != 0) compact_pos_limit = pinned_areas[0];
 
 #if _DEBUG
-    int pin_size = 0;
+    POINTER_SIZE_INT pin_size = 0;
     for(pinned_areas_unsorted_t::iterator iii = pinned_areas_unsorted.begin();
             iii != pinned_areas_unsorted.end(); ++iii) {
         unsigned char *start = *iii; ++iii;
@@ -245,7 +245,7 @@
     partial_sort_copy(pinned_areas_unsorted.begin(), pinned_areas_unsorted.end(), pinned_areas.begin(),
pinned_areas.end());
 
 #if _DEBUG
-    int sorted_pin_size = 0;
+    POINTER_SIZE_INT sorted_pin_size = 0;
     for(unsigned ii = 0; ii < pinned_areas.size(); ii+=2) {
         TRACE2("gc.pin", "pinned_areas[" << ii << "] = " << pinned_areas[ii]);
         TRACE2("gc.pin", "pinned_areas[" << ii+1 << "] = " << pinned_areas[ii+1]);
@@ -272,10 +272,10 @@
 
     int *mark_words = (int*) mark_bits;
     // Searching marked bits
-    unsigned start = (unsigned)(heap.compaction_region_start() - heap_base) / GC_OBJECT_ALIGNMENT
/ sizeof(int) / 8;
-    unsigned end = (unsigned)(heap.compaction_region_end() - heap_base + GC_OBJECT_ALIGNMENT
* sizeof(int) * 8 - 1) / GC_OBJECT_ALIGNMENT / sizeof(int) / 8;
+    size_t start = (size_t)(heap.compaction_region_start() - heap_base) / GC_OBJECT_ALIGNMENT
/ sizeof(int) / 8;
+    size_t end = (size_t)(heap.compaction_region_end() - heap_base + GC_OBJECT_ALIGNMENT
* sizeof(int) * 8 - 1) / GC_OBJECT_ALIGNMENT / sizeof(int) / 8;
     if (end > mark_bits_size/sizeof(int)) end = mark_bits_size/sizeof(int);
-    for(unsigned i = start; i < end; i++) {
+    for(size_t i = start; i < end; i++) {
         // no marked bits in word - skip
 
         int word = mark_words[i];

Modified: harmony/enhanced/drlvm/trunk/vm/gc_cc/src/gc_for_vm.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_cc/src/gc_for_vm.cpp?view=diff&rev=512330&r1=512329&r2=512330
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_cc/src/gc_for_vm.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_cc/src/gc_for_vm.cpp Tue Feb 27 09:27:57 2007
@@ -126,8 +126,9 @@
 }
 
 Managed_Object_Handle gc_alloc_fast(unsigned in_size, 
-                                             Allocation_Handle ah,
+                                             Allocation_Handle _ah,
                                              void *thread_pointer) {
+    VT32 ah = (VT32) _ah;
 
     //TRACE2("gc.alloc", "gc_alloc_fast");
     assert((in_size % GC_OBJECT_ALIGNMENT) == 0);
@@ -175,8 +176,9 @@
 }
 
 Managed_Object_Handle gc_alloc(unsigned in_size, 
-                                        Allocation_Handle ah,
+                                        Allocation_Handle _ah,
                                         void *thread_pointer) {
+    VT32 ah = (VT32) _ah;
     TRACE2("gc.alloc", "gc_alloc: " << in_size);
     assert((in_size % GC_OBJECT_ALIGNMENT) == 0);
     assert (ah);

Modified: harmony/enhanced/drlvm/trunk/vm/gc_cc/src/gc_types.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_cc/src/gc_types.h?view=diff&rev=512330&r1=512329&r2=512330
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_cc/src/gc_types.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_cc/src/gc_types.h Tue Feb 27 09:27:57 2007
@@ -104,6 +104,8 @@
 
 // Heap layout
 #define RESERVED_FOR_HEAP_NULL (4 * 32)
+#define RESERVED_FOR_LAST_HASH (GC_OBJECT_ALIGNMENT)
+
 
 // FLAGS
 extern const char *lp_hint; // Use large pages
@@ -205,10 +207,12 @@
 unsigned
 GC_VTable_Info::array_size(int length) {
     assert(is_array());
-    unsigned f = flags();
-    unsigned element_shift = f >> GC_VT_ARRAY_ELEMENT_SHIFT;
-    unsigned first_element = element_shift >> (GC_VT_ARRAY_FIRST_SHIFT - GC_VT_ARRAY_ELEMENT_SHIFT);
-    return (first_element + (length << (element_shift & GC_VT_ARRAY_ELEMENT_MASK))
+ (GC_OBJECT_ALIGNMENT - 1)) & ~(GC_OBJECT_ALIGNMENT - 1);
+    POINTER_SIZE_INT f = flags();
+    POINTER_SIZE_INT element_shift = f >> GC_VT_ARRAY_ELEMENT_SHIFT;
+    POINTER_SIZE_INT first_element = element_shift >> (GC_VT_ARRAY_FIRST_SHIFT - GC_VT_ARRAY_ELEMENT_SHIFT);
+    POINTER_SIZE_INT size = first_element + (length << (element_shift & GC_VT_ARRAY_ELEMENT_MASK));
+    POINTER_SIZE_INT aligned_size = (size + (GC_OBJECT_ALIGNMENT - 1)) & ~(GC_OBJECT_ALIGNMENT
- 1);
+    return (unsigned) aligned_size;
 }
 
 static inline int get_object_size(Partial_Reveal_Object *obj, GC_VTable_Info *gcvt) {
@@ -292,7 +296,7 @@
 extern Ptr heap_base;
 
 extern int pending_finalizers;
-extern uint32 chunk_size;
+extern POINTER_SIZE_INT chunk_size;
 extern bool cleaning_needed;
 extern std::vector<unsigned char*> pinned_areas;
 extern unsigned pinned_areas_pos;
@@ -312,7 +316,7 @@
 
 // for slide compaction algorithms
 extern unsigned char *mark_bits;
-extern int mark_bits_size;
+extern size_t mark_bits_size;
 
 
 // FUNCTIONS PROTOTYPES
@@ -325,6 +329,8 @@
 unsigned char * slide_gc(int size);
 unsigned char* allocate_from_chunk(int size);
 
+void enable_heap_region(void *start, size_t size);
+void disable_heap_region(void *start, size_t size);
 void gc_reserve_mark_bits();
 void gc_unreserve_mark_bits();
 void gc_allocate_mark_bits();

Modified: harmony/enhanced/drlvm/trunk/vm/gc_cc/src/init.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_cc/src/init.cpp?view=diff&rev=512330&r1=512329&r2=512330
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_cc/src/init.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_cc/src/init.cpp Tue Feb 27 09:27:57 2007
@@ -42,12 +42,10 @@
 unsigned int heap_mark_phase;
 
 HeapSegment heap;
-uint32 chunk_size;
+POINTER_SIZE_INT chunk_size;
 
 int pending_finalizers = false;
 
-#define RESERVED_FOR_LAST_HASH 4
-
 #define MB * (1024 * 1024)
 size_t HEAP_SIZE_DEFAULT = 256 MB;
 
@@ -65,6 +63,46 @@
 const char *lp_hint = NULL;
 bool jvmti_heap_iteration = false;
 
+#ifdef _WIN32
+ /* WINDOWS */
+static const void* MEM_FAILURE = 0;
+void* mem_reserve(size_t size) {
+    return VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_READWRITE);
+}
+void  mem_unreserve(void *ptr, size_t size) {
+    bool UNUSED res = VirtualFree(ptr, 0, MEM_RELEASE);
+	int err = GetLastError();
+    assert(res);
+}
+
+void  mem_commit(void *ptr, size_t size) {
+    bool UNUSED res = VirtualAlloc(ptr, size, MEM_COMMIT, PAGE_READWRITE);
+    assert(res);
+}
+
+void  mem_decommit(void *ptr, size_t size) {
+    bool UNUSED res = VirtualFree(ptr, size, MEM_DECOMMIT);
+    assert (res);
+}
+#else
+ /* LINUX */
+static const void* MEM_FAILURE = MAP_FAILED;
+void* mem_reserve(size_t size) {
+    return mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+}
+void  mem_unreserve(void *ptr, size_t size) {
+    int UNUSED res = munmap(ptr, size);
+    assert (res != -1);
+}
+void* mem_commit(void *ptr, size_t size) {
+}
+void mem_decommit(void *ptr, size_t size) {
+    UNUSED void *res = mmap(ptr, size, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE |
MAP_ANONYMOUS, -1, 0);
+    assert(res != MAP_FAILED);
+}
+#endif
+
+
 static size_t get_size_property(const char* name) 
 {
     char* size_string = get_property(name, VM_PROPERTIES);
@@ -179,38 +217,12 @@
     }
 }
 
-#ifdef _WIN32
-static inline void *reserve_mem(size_t size) {
-    return VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_READWRITE);
+void enable_heap_region(void *start, size_t size) {
+    if (!lp_hint) mem_commit(start, size);
 }
-static const void* RESERVE_FAILURE = 0;
-#else
-static inline void *reserve_mem(size_t size) {
-#ifdef POINTER64
-    /* We have plenty of address space, let's protect unaccessible part of heap
-     * to find some of bad pointers. */
-    size_t four_gig = 4 * 1024 * (size_t) 1024 * 1024;
-    size_t padding = 4 * 1024 * (size_t) 1024 * 1024;
-    four_gig = 0;
-    padding = 0;
-    void *addr = mmap(0, padding + max_heap_size + four_gig, PROT_READ | PROT_WRITE,
-            MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-    assert(addr != MAP_FAILED);
-    UNUSED int err = mprotect((Ptr)addr, padding, PROT_NONE);
-    assert(!err);
-    err = mprotect((Ptr)addr + padding + max_heap_size,
-                    four_gig, PROT_NONE);
-    assert(!err);
-    return (Ptr)addr + padding;
-#else
-    return mmap(0, max_heap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1,
0);
-#endif
+void disable_heap_region(void *start, size_t size) {
+    if (!lp_hint) mem_decommit(start, size);
 }
-static const void* RESERVE_FAILURE = MAP_FAILED;
-#endif
-
-
-
 
 void init_mem() {
     parse_configuration_properties();
@@ -236,14 +248,14 @@
     }
 
     if (heap_base == NULL) {
-        heap_base = (unsigned char*) reserve_mem(max_heap_size);
-        if (heap_base == RESERVE_FAILURE) {
+        heap_base = (unsigned char*) mem_reserve(max_heap_size);
+        if (heap_base == (Ptr) MEM_FAILURE) {
             size_t dec = 100 * 1024 * 1024;
             max_heap_size = max_heap_size / dec * dec;
 
             while(true) {
-                heap_base = (unsigned char*) reserve_mem(max_heap_size);
-                if (heap_base != RESERVE_FAILURE) break;
+                heap_base = (unsigned char*) mem_reserve(max_heap_size);
+                if (heap_base != (Ptr) MEM_FAILURE) break;
                 max_heap_size -= dec;
                 assert(max_heap_size > 0);
             }
@@ -262,18 +274,16 @@
     heap.size = min_heap_size;
     heap.max_size = max_heap_size;
     heap.roots_start = heap.roots_pos = heap.roots_end =
-        heap.base + heap.max_size - RESERVED_FOR_LAST_HASH;
+        heap.base + heap.max_size;
+
+    enable_heap_region(heap.base, heap.size);
 
-#ifdef _WIN32
-    void *res;
-    if (heap_base && !lp_hint) {
-        res = VirtualAlloc(heap.base, heap.size, MEM_COMMIT, PAGE_READWRITE);
-        if (!res) LDIE(2, "Can't create heap_L");
-    }
-#endif
     chunk_size = round_down(heap.size / 10, 65536);
     init_gcvt();
-    gc_reserve_mark_bits();
+
+    mark_bits_size = max_heap_size / sizeof(void*) / 8;
+    mark_bits = (Ptr) mem_reserve(mark_bits_size);
+    assert(mark_bits != MEM_FAILURE);
 }
 
 void gc_init() {
@@ -297,39 +307,12 @@
         << "gc/user " << (int)(total_gc_time*100.f/total_user_time) <<
" %"
     );
     INFO2("gc.init", "gc_wrapup called");
-    gc_unreserve_mark_bits();
+    mem_unreserve(heap_base, max_heap_size);
+    mem_unreserve(mark_bits, mark_bits_size);
     deinit_gcvt();
-#ifdef _WIN32
-    bool UNUSED res = VirtualFree(heap_base, max_heap_size, MEM_DECOMMIT);
-    assert (res);
-#else
-    int UNUSED res = munmap(heap_base, max_heap_size);
-    assert (res != -1);
-#endif
     INFO2("gc.init", "gc_wrapup done");
 }
 
-void gc_reserve_mark_bits() {
-    mark_bits_size = max_heap_size / sizeof(void*) / 8;
-#ifdef _WIN32
-    mark_bits = (unsigned char*) VirtualAlloc(NULL, mark_bits_size, MEM_RESERVE, PAGE_READWRITE);
-    assert(mark_bits);
-#else
-    mark_bits = (unsigned char*) mmap(0, mark_bits_size, PROT_READ | PROT_WRITE, MAP_PRIVATE
| MAP_ANONYMOUS, -1, 0);
-    assert(mark_bits != MAP_FAILED);
-#endif
-}
-
-void gc_unreserve_mark_bits() {
-#ifdef _WIN32
-    bool UNUSED res = VirtualFree(mark_bits, 0, MEM_RELEASE);
-    assert(res);
-#else
-    int UNUSED res = munmap(mark_bits, mark_bits_size);
-    assert(res != -1);
-#endif
-}
-
 static unsigned char *mark_bits_allocated_start;
 static unsigned char *mark_bits_allocated_end;
 
@@ -340,23 +323,11 @@
     int page = 4096; // FIXME
     mark_bits_allocated_start = (unsigned char*)((POINTER_SIZE_INT)start & ~(page - 1));
     mark_bits_allocated_end = (unsigned char*)(((POINTER_SIZE_INT)end + page - 1) & ~(page
- 1));
-#ifdef _WIN32
-    unsigned char *res = (unsigned char*) VirtualAlloc(mark_bits_allocated_start,
-            mark_bits_allocated_end - mark_bits_allocated_start, MEM_COMMIT, PAGE_READWRITE);
-    assert(res);
-#endif
+    mem_commit(mark_bits_allocated_start, mark_bits_allocated_end - mark_bits_allocated_start);
 }
 
 void gc_deallocate_mark_bits() {
-#ifdef _WIN32
-    bool UNUSED res = VirtualFree(mark_bits_allocated_start,
-            mark_bits_allocated_end - mark_bits_allocated_start, MEM_DECOMMIT);
-    assert(res);
-#else
-    void UNUSED *res = mmap(mark_bits, mark_bits_size, PROT_READ | PROT_WRITE, MAP_FIXED
| MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-    assert(res == (void*)mark_bits);
-    assert(mark_bits[0] == 0);
-#endif
+    mem_decommit(mark_bits, mark_bits_size);
 }
 
 void heap_extend(size_t size) {
@@ -365,10 +336,8 @@
     if (size > max_size) size = max_size;
     if (size <= heap.size) return;
 
-#ifdef _WIN32
-    void* UNUSED res = VirtualAlloc(heap.base + heap.size, size - heap.size, MEM_COMMIT,
PAGE_READWRITE);
-    assert(res);
-#endif
+    enable_heap_region(heap.base + heap.size, size - heap.size);
+
     heap.size = size;
     unsigned char *old_ceiling = heap.ceiling;
     heap.ceiling = heap.base + heap.size - RESERVED_FOR_LAST_HASH;
@@ -391,13 +360,7 @@
     }
     if (size >= heap.size) return;
 
-#ifdef _WIN32
-    bool UNUSED res = VirtualFree(heap.base + size, heap.size - size, MEM_DECOMMIT);
-    assert(res);
-#else
-    void UNUSED *res = mmap(heap.base + size, heap.size - size, PROT_READ | PROT_WRITE, MAP_FIXED
| MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-    assert(res == (void*)(heap.base + size));
-#endif
+    disable_heap_region(heap.base + size, heap.size - size);
 
     heap.size = size;
     heap.ceiling = heap.base + heap.size - RESERVED_FOR_LAST_HASH;

Modified: harmony/enhanced/drlvm/trunk/vm/gc_cc/src/slot.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_cc/src/slot.cpp?view=diff&rev=512330&r1=512329&r2=512330
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_cc/src/slot.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_cc/src/slot.cpp Tue Feb 27 09:27:57 2007
@@ -181,8 +181,10 @@
 
 void init_slots() {
     heap.roots_start = heap.roots_pos = heap.roots_end - 1024 * 1024;
-    if (heap.ceiling > heap.roots_start) heap.ceiling = heap.roots_start;
+    if (heap.ceiling + RESERVED_FOR_LAST_HASH > heap.roots_start)
+        heap.ceiling = heap.roots_start - RESERVED_FOR_LAST_HASH;
     heap_null = (Partial_Reveal_Object*) heap.base;
+    enable_heap_region(heap.roots_start, heap.roots_end - heap.roots_start);
 }
 
 void roots_clear() {

Modified: harmony/enhanced/drlvm/trunk/vm/gc_cc/src/slot.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_cc/src/slot.h?view=diff&rev=512330&r1=512329&r2=512330
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_cc/src/slot.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_cc/src/slot.h Tue Feb 27 09:27:57 2007
@@ -52,7 +52,7 @@
     void* ptr() { return (void*) s; }
 
 #ifdef POINTER64
-    void write(Partial_Reveal_Object *obj) { *s = (Ptr)obj - heap_base; }
+    void write(Partial_Reveal_Object *obj) { *s = (Reference)((Ptr)obj - heap_base); }
     Partial_Reveal_Object *read() { return (Partial_Reveal_Object*)(heap_base + *s); }
 
     void write_raw(Reference data) { *s = data; }
@@ -86,7 +86,7 @@
   }
 
   inline Reference pointer_to_fw(Partial_Reveal_Object *obj) {
-      return (Ptr)obj - (Ptr) heap_base + FORWARDING_BIT;
+      return (Reference)((Ptr)obj - (Ptr) heap_base) + FORWARDING_BIT;
   }
       
   extern Slot make_direct_root(Partial_Reveal_Object **root);



Mime
View raw message