harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From x..@apache.org
Subject svn commit: r611186 [1/3] - in /harmony/enhanced/drlvm/trunk/vm/gc_gen/src: common/ finalizer_weakref/ gen/ los/ mark_compact/ mark_sweep/ move_compact/ semi_space/ thread/ trace_forward/ utils/ verify/
Date Fri, 11 Jan 2008 14:38:50 GMT
Author: xli
Date: Fri Jan 11 06:38:32 2008
New Revision: 611186

URL: http://svn.apache.org/viewvc?rev=611186&view=rev
Log:
HARMONY-5367 : [drlvm][gc] implementation of semi-space GC prototype, with both generational and non-generational modes. Also some code refactors when this new GC is introduced. The intention is to make GC be able to switch back and forth between different algorithms at runtime.

Added:
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_barrier.cpp   (with props)
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_barrier.h   (with props)
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen_utils.cpp   (with props)
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/move_compact/
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/move_compact/gc_mc.h   (with props)
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/semi_space/sspace.cpp   (with props)
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/semi_space/sspace_alloc.cpp   (with props)
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/semi_space/sspace_forward.cpp   (with props)
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/semi_space/sspace_gen_ss_pool.cpp   (with props)
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/semi_space/sspace_nongen_ss_pool.cpp   (with props)
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/verify/verify_blocked_space.cpp   (with props)
Removed:
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gc_for_barrier.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gc_for_barrier.h
Modified:
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/collection_scheduler.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/collection_scheduler.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_block.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_block.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_common.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_common.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_concurrent.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_concurrent.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_class.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_vm.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_metadata.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_metadata.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_platform.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_space.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/interior_pointer.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/mark_scan_pool.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/object_status.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/space_tuner.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/finalizer_weakref/finalizer_weakref.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/finalizer_weakref/finalizer_weakref.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/finalizer_weakref/finalizer_weakref_metadata.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen_adapt.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen_stats.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen_stats.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/los/free_area_pool.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/los/free_area_pool.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/los/lspace_alloc_collect.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/mark_compact/fallback_mark_scan.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/mark_compact/mspace.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/mark_compact/mspace.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/mark_compact/mspace_alloc.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/mark_compact/mspace_move_compact.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/mark_sweep/gc_ms.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/mark_sweep/gc_ms.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/mark_sweep/wspace.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/mark_sweep/wspace_alloc.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/mark_sweep/wspace_alloc.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/mark_sweep/wspace_chunk.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/mark_sweep/wspace_chunk.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/mark_sweep/wspace_mark_sweep.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/mark_sweep/wspace_sweep_concurrent.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/semi_space/sspace.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/thread/collector.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/thread/collector.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/thread/collector_alloc.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/thread/gc_thread.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/thread/gc_thread.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/thread/marker.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/thread/marker.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/thread/mutator.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/thread/mutator.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/thread/mutator_alloc.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/trace_forward/fspace.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/trace_forward/fspace.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/trace_forward/fspace_alloc.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/trace_forward/sspace_temp.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/bit_ops.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/sync_queue.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/verify/verifier_common.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/verify/verifier_scanner.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/verify/verify_gc_effect.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/verify/verify_live_heap.cpp
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/verify/verify_live_heap.h

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/collection_scheduler.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/collection_scheduler.cpp?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/collection_scheduler.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/collection_scheduler.cpp Fri Jan 11 06:38:32 2008
@@ -23,6 +23,8 @@
 #include "gc_concurrent.h"
 #include "../verify/verify_live_heap.h"
 
+#define NUM_TRIAL_COLLECTION 10
+
 static int64 time_delay_to_start_mark = 0;
 
 void collection_scheduler_initialize(GC* gc)
@@ -91,7 +93,7 @@
   return FALSE;
 }
 
-void gc_update_collection_scheduler(GC* gc, int64 mutator_time, int64 mark_time)
+void gc_update_collection_scheduler(GC* gc, int64 time_mutator, int64 time_mark)
 {
   //FIXME: support GEN GC.
 #ifdef USE_MARK_SWEEP_GC
@@ -109,8 +111,8 @@
   collection_scheduler->num_obj_traced_window[slot_index] = space_stat->num_live_obj;
   collection_scheduler->size_alloced_window[slot_index] = space_stat->last_size_free_space;
 
-  int64 time_mutator = mutator_time;
-  int64 time_mark = mark_time;
+  collection_scheduler->last_mutator_time = time_mutator;
+  collection_scheduler->last_collector_time = time_mark;
   
   collection_scheduler->alloc_rate_window[slot_index] 
     = time_mutator == 0 ? 0 : (float)collection_scheduler->size_alloced_window[slot_index] / time_mutator; 
@@ -128,7 +130,17 @@
   for(i = 0; i < collection_scheduler->num_slot_in_window; i++){
     sum_alloc_rate += collection_scheduler->alloc_rate_window[i];
     sum_trace_rate += collection_scheduler->trace_rate_window[i];
-    
+  }
+
+  TRACE2("gc.con","Allocation Rate: ");
+  for(i = 0; i < collection_scheduler->num_slot_in_window; i++){
+    TRACE2("gc.con",i+1<<"  "<<collection_scheduler->alloc_rate_window[i]);
+  }
+  
+  TRACE2("gc.con","Tracing Rate: ");
+
+  for(i = 0; i < collection_scheduler->num_slot_in_window; i++){
+    TRACE2("gc.con",i+1<<"  "<<collection_scheduler->trace_rate_window[i]);
   }
 
   float average_alloc_rate = sum_alloc_rate / collection_scheduler->num_slot_in_window;
@@ -145,7 +157,7 @@
       if(gc_concurrent_match_algorithm(OTF_REM_OBJ_SNAPSHOT_ALGO)||gc_concurrent_match_algorithm(OTF_REM_NEW_TARGET_ALGO)){
         collection_scheduler->time_delay_to_start_mark = (int64)((time_alloc_expected - time_trace_expected)*0.65);
       }else if(gc_concurrent_match_algorithm(MOSTLY_CONCURRENT_ALGO)){
-        collection_scheduler->time_delay_to_start_mark = (int64)(mutator_time * 0.6);
+        collection_scheduler->time_delay_to_start_mark = (int64)(time_mutator* 0.6);
       }
       
     }else{
@@ -154,6 +166,7 @@
 
     time_delay_to_start_mark = collection_scheduler->time_delay_to_start_mark;
   }
+  INFO2("gc.con","[Concurrent GC] concurrent marking will delay "<<(unsigned int)(time_delay_to_start_mark>>10)<<" ms ");
   //[DEBUG] set to 0 for debugging.
   //time_delay_to_start_mark = 0; 
 #endif  
@@ -161,8 +174,45 @@
   
 }
 
+unsigned int gc_decide_marker_number(GC* gc)
+{
+  unsigned int num_active_marker;
+  Collection_Scheduler* collection_scheduler = gc->collection_scheduler;   
+
+  if(NUM_TRIAL_COLLECTION == 0 || gc->num_collections < NUM_TRIAL_COLLECTION){
+    /*Start trial cycle, collection set to 1 in trial cycle and */
+    num_active_marker = 1;
+  }else{
+    num_active_marker = collection_scheduler->last_marker_num;
+    int64 c_time = collection_scheduler->last_collector_time;
+    int64 m_time = collection_scheduler->last_mutator_time;
+    int64 d_time = collection_scheduler->time_delay_to_start_mark;
+
+    if(num_active_marker == 0) num_active_marker = 1;
+
+    if(c_time > m_time || (float)d_time > (m_time - c_time) * 0.75){      
+      INFO2("gc.con","[Concurrent GC] increase marker number.");
+      num_active_marker ++;
+      if(num_active_marker > gc->num_markers) num_active_marker = gc->num_markers;
+    }else if((float)d_time < (m_time - c_time) * 0.25){
+      INFO2("gc.con","[Concurrent GC] decrease marker number.");
+      num_active_marker --;
+      if(num_active_marker == 0)  num_active_marker = 1;
+    }
+  }
+  
+  INFO2("gc.con","[Concurrent GC] marker num : "<<num_active_marker<<" ");
+
+  
+  collection_scheduler->last_marker_num = num_active_marker;
+  return num_active_marker;
+}
+
 Boolean gc_try_schedule_collection(GC* gc, unsigned int gc_cause)
 {
+
+  if(!try_lock(gc->collection_scheduler_lock)) return FALSE;
+
   gc_check_concurrent_phase(gc);
 
   if(gc_need_prepare_rootset(gc)){
@@ -171,26 +221,35 @@
   }
   
   if(gc_need_start_concurrent_mark(gc)){
+    vm_gc_lock_enum();
+    INFO2("gc.con", "\nCon GC: concurrent mark start ...\n");
     gc_start_concurrent_mark(gc);
+    vm_gc_unlock_enum();
+    unlock(gc->collection_scheduler_lock);
     return TRUE;
   }
 
   if(gc_need_start_concurrent_sweep(gc)){
     gc->num_collections++;
     gc_start_concurrent_sweep(gc);
+    unlock(gc->collection_scheduler_lock);
     return TRUE;
   }
 
   if(gc_need_reset_status(gc)){
+    vm_gc_lock_enum();
     int disable_count = hythread_reset_suspend_disable();    
+    gc_prepare_rootset(gc);
     gc_reset_after_concurrent_collection(gc);
     vm_resume_threads_after();    
     hythread_set_suspend_disable(disable_count);
+    vm_gc_unlock_enum();
+    unlock(gc->collection_scheduler_lock);
+    return TRUE;
   }
-
+  unlock(gc->collection_scheduler_lock);
   return FALSE;
 
 }
-
 
 

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/collection_scheduler.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/collection_scheduler.h?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/collection_scheduler.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/collection_scheduler.h Fri Jan 11 06:38:32 2008
@@ -27,7 +27,11 @@
   /*mark schedule */
   int64 time_delay_to_start_mark;
   
-  /**/
+  int64 last_mutator_time;
+  int64 last_collector_time;
+
+  unsigned int last_marker_num;
+
   unsigned int num_slot_in_window;
   unsigned int last_slot_index_in_window;
   
@@ -43,9 +47,9 @@
 void gc_update_collection_scheduler(GC* gc, int64 mutator_time, int64 mark_time);
 Boolean gc_try_schedule_collection(GC* gc, unsigned int gc_cause);
 Boolean gc_need_start_concurrent_mark(GC* gc);
+unsigned int gc_decide_marker_number(GC* gc);
 
 
 #endif
-
 
 

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_block.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_block.cpp?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_block.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_block.cpp Fri Jan 11 06:38:32 2008
@@ -45,6 +45,31 @@
   }
 }
 
+#ifndef STATIC_NOS_MAPPING
+void blocked_space_adjust(Blocked_Space* space, void* new_space_start, POINTER_SIZE_INT new_space_size)
+{    
+  space->heap_start = new_space_start;
+  space->blocks = (Block*)new_space_start;
+  space->committed_heap_size = new_space_size;
+  space->reserved_heap_size = new_space_size;
+  space->num_managed_blocks = (unsigned int)(new_space_size >> GC_BLOCK_SHIFT_COUNT);
+  space->num_total_blocks = space->num_managed_blocks;
+  space->first_block_idx = ((Block_Header*)new_space_start)->block_idx;
+  space->ceiling_block_idx = space->first_block_idx + space->num_managed_blocks - 1;
+ 	space->num_used_blocks = 0;
+
+  void* new_space_end = (void*)((POINTER_SIZE_INT)new_space_start + new_space_size);
+  space->heap_end = new_space_end;
+
+  /* we can't set free_block_idx here! because the adjusted space might have some used block inside. 
+     e.g., when it's used to adjust MOS after a collection.
+  space->free_block_idx = space->first_block_idx;
+  */
+  
+  return;
+}
+#endif /* #ifndef STATIC_NOS_MAPPING */
+
 void blocked_space_shrink(Blocked_Space* space, unsigned int changed_size)
 {
   unsigned int block_dec_count = changed_size >> GC_BLOCK_SHIFT_COUNT;

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_block.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_block.h?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_block.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_block.h Fri Jan 11 06:38:32 2008
@@ -51,6 +51,8 @@
   unsigned int num_multi_block; /*number of block in large block*/
 #endif
   volatile unsigned int status;
+
+  volatile unsigned int num_live_objs; /* for verification debugging */
   
   /* following three fields are used only in parallel sliding compaction */
   volatile unsigned int dest_counter;
@@ -125,6 +127,16 @@
 #endif
 }
 
+inline void block_reset(Block_Header* block)
+{
+  if(block->status == BLOCK_FREE) return;
+  block->src = NULL;
+  block->next_src = NULL;
+  assert(!block->dest_counter);
+  block->status = BLOCK_FREE; 
+  block->free = block->base;
+}
+
 inline void block_destruct(Block_Header* block)
 {
 #ifdef USE_32BITS_HASHCODE
@@ -265,7 +277,6 @@
 /* blocked_space hashcode_buf ops --> */
 
 #endif //#ifndef _BLOCK_H_
-
 
 
 

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_common.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_common.cpp?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_common.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_common.cpp Fri Jan 11 06:38:32 2008
@@ -26,6 +26,7 @@
 #include "../finalizer_weakref/finalizer_weakref.h"
 #include "../gen/gen.h"
 #include "../mark_sweep/gc_ms.h"
+#include "../move_compact/gc_mc.h"
 #include "../common/space_tuner.h"
 #include "interior_pointer.h"
 #include "collection_scheduler.h"
@@ -41,6 +42,8 @@
 extern POINTER_SIZE_INT NOS_SIZE;
 extern POINTER_SIZE_INT MIN_NOS_SIZE;
 extern POINTER_SIZE_INT INIT_LOS_SIZE;
+extern POINTER_SIZE_INT TOSPACE_SIZE;
+extern POINTER_SIZE_INT MOS_RESERVE_SIZE;
 
 extern Boolean FORCE_FULL_COMPACT;
 
@@ -60,13 +63,6 @@
 extern Boolean IS_MOVE_COMPACT;
 extern Boolean USE_CONCURRENT_GC;
 
-#if defined(ALLOC_ZEROING) && defined(ALLOC_PREFETCH)
-POINTER_SIZE_INT PREFETCH_DISTANCE = 1024;
-POINTER_SIZE_INT ZEROING_SIZE = 256;
-POINTER_SIZE_INT PREFETCH_STRIDE = 64;
-Boolean PREFETCH_ENABLED = FALSE;
-#endif
-
 static int get_int_property(const char *property_name)
 {
     assert(property_name);
@@ -240,6 +236,14 @@
     gc->generate_barrier = generate_barrier || gc->generate_barrier;
   }
 
+  if (is_property_set("gc.tospace_size", VM_PROPERTIES) == 1) {
+    TOSPACE_SIZE = get_size_property("gc.tospace_size");
+  }
+
+  if (is_property_set("gc.mos_reserve_size", VM_PROPERTIES) == 1) {
+    MOS_RESERVE_SIZE = get_size_property("gc.mos_reserve_size");
+  }
+
   if (is_property_set("gc.nos_partial_forward", VM_PROPERTIES) == 1) {
     NOS_PARTIAL_FORWARD = get_boolean_property("gc.nos_partial_forward");
   }
@@ -328,25 +332,25 @@
   }
 
   if(is_property_set("gc.prefetch_distance",VM_PROPERTIES)==1) {
-  	PREFETCH_DISTANCE = get_size_property("gc.prefetch_distance");
-  	if(!PREFETCH_ENABLED) {
+    PREFETCH_DISTANCE = get_size_property("gc.prefetch_distance");
+    if(!PREFETCH_ENABLED) {
       WARN2("gc.prefetch_distance","Warning: Prefetch distance set with Prefetch disabled!");
     }
   }
 
   if(is_property_set("gc.prefetch_stride",VM_PROPERTIES)==1) {
-	PREFETCH_STRIDE = get_size_property("gc.prefetch_stride");
-	if(!PREFETCH_ENABLED) {
-		WARN2("gc.prefetch_stride","Warning: Prefetch stride set  with Prefetch disabled!");
-	}	
+    PREFETCH_STRIDE = get_size_property("gc.prefetch_stride");
+    if(!PREFETCH_ENABLED) {
+      WARN2("gc.prefetch_stride","Warning: Prefetch stride set  with Prefetch disabled!");
+    }  
   }
   
   if(is_property_set("gc.zeroing_size",VM_PROPERTIES)==1) {
-  	ZEROING_SIZE = get_size_property("gc.zeroing_size");
-  	if(!PREFETCH_ENABLED) {
-  		WARN2("gc.zeroing_size","Warning: Zeroing size set with Prefetch disabled!");
-  	}	
-  }	 
+    ZEROING_SIZE = get_size_property("gc.zeroing_size");
+    if(!PREFETCH_ENABLED) {
+      WARN2("gc.zeroing_size","Warning: Zeroing size set with Prefetch disabled!");
+    }  
+  }   
 #endif
 
   return;
@@ -418,7 +422,7 @@
   
   collection_start_time = time_now();
   int64 mutator_time = collection_start_time - collection_end_time;
-  
+
   /* FIXME:: before mutators suspended, the ops below should be very careful
      to avoid racing with mutators. */
   gc->num_collections++;
@@ -521,17 +525,16 @@
   vm_reclaim_native_objs();
   gc->in_collection = FALSE;
 
-  gc_reset_collector_state(gc);
-
   gc_clear_dirty_set(gc);
   
   vm_resume_threads_after();
   assert(hythread_is_suspend_enabled());
   hythread_set_suspend_disable(disable_count);
   INFO2("gc.process", "GC: GC end\n");
+  int64 pause_time = time_now()-collection_start_time;
+  INFO2("gc.con","pause time:  "<<((unsigned int)(pause_time>>10))<<"  ms \n");
   return;
 }
-
 
 
 

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_common.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_common.h?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_common.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_common.h Fri Jan 11 06:38:32 2008
@@ -36,7 +36,7 @@
 #include "gc_for_class.h"
 #include "gc_platform.h"
 
-#include "../gen/gc_for_barrier.h"
+#include "../common/gc_for_barrier.h"
 
 /* 
 #define USE_MARK_SWEEP_GC  //define it to only use Mark-Sweep GC (no NOS, no LOS).
@@ -174,11 +174,8 @@
   else
     return (REF) ((POINTER_SIZE_INT) p_obj - HEAP_NULL);
 #else
-
-        return (REF)p_obj;
-
+    return (REF)p_obj;
 #endif
-
 }
 
 FORCE_INLINE Partial_Reveal_Object *ref_to_obj_ptr(REF ref)
@@ -190,9 +187,7 @@
   return (Partial_Reveal_Object *)(HEAP_NULL + ref);
 
 #else
-
-        return (Partial_Reveal_Object *)ref;
-
+  return (Partial_Reveal_Object *)ref;
 #endif
 
 }
@@ -272,7 +267,7 @@
 }
 
 inline Boolean obj_is_fw_in_oi(Partial_Reveal_Object *obj) 
-{  return (get_obj_info_raw(obj) & CONST_FORWARD_BIT); }
+{  return (Boolean)(get_obj_info_raw(obj) & CONST_FORWARD_BIT); }
 
 inline void obj_set_fw_in_oi(Partial_Reveal_Object *obj,void *dest)
 {  
@@ -348,7 +343,7 @@
 inline Boolean obj_unmark_in_oi(Partial_Reveal_Object* p_obj)
 {
   Obj_Info_Type info = get_obj_info_raw(p_obj);
-  info = info & DUAL_MARKBITS_MASK;
+  info = info & ~FLIP_MARK_BIT;
   set_obj_info(p_obj, info);
   return TRUE;
 }
@@ -361,6 +356,7 @@
 
 #endif /* MARK_BIT_FLIPPING */
 
+/********************* for concurrent GC *******************************/
 inline Boolean obj_is_dirty_in_oi(Partial_Reveal_Object* p_obj)
 {
   Obj_Info_Type info = get_obj_info_raw(p_obj);
@@ -390,11 +386,31 @@
   obj_alloced_live = TRUE;  
 }
 
-inline void gc_disenable_alloc_obj_live()
+inline void gc_disable_alloc_obj_live()
 { 
   obj_alloced_live = FALSE; 
 }
 
+/***************************************************************/
+
+inline Boolean obj_is_survivor(Partial_Reveal_Object* p_obj)
+{
+  return get_obj_info_raw(p_obj) & OBJ_AGE_BIT;
+}
+
+inline void obj_set_age_bit(Partial_Reveal_Object* p_obj)
+{
+  Obj_Info_Type oi = get_obj_info_raw(p_obj);
+  return set_obj_info( p_obj, oi |OBJ_AGE_BIT) ;
+}
+
+inline void obj_clear_age_bit(Partial_Reveal_Object* p_obj)
+{
+  Obj_Info_Type oi = get_obj_info_raw(p_obj);
+  return set_obj_info( p_obj, oi & ~OBJ_AGE_BIT) ;
+}
+
+/***************************************************************/
 /* all GCs inherit this GC structure */
 struct Marker;
 struct Mutator;
@@ -454,7 +470,7 @@
   SpinLock concurrent_mark_lock;
   SpinLock enumerate_rootset_lock;
   SpinLock concurrent_sweep_lock;
-  
+  SpinLock collection_scheduler_lock;
   
   /* system info */
   unsigned int _system_alloc_unit;
@@ -495,9 +511,6 @@
   return (Boolean)(gc->collect_kind & multi_kinds);
 }
 
-inline void gc_reset_collector_state(GC* gc)
-{ gc->num_active_collectors = 0;}
-
 inline unsigned int gc_get_processor_num(GC* gc) { return gc->_num_processors; }
 
 void gc_parse_options(GC* gc);
@@ -546,4 +559,5 @@
 {  return ((p_obj >= los_boundary) || (*p_global_lspace_move_obj)); }
 
 extern Boolean TRACE_JLC_VIA_VTABLE;
+
 #endif //_GC_COMMON_H_

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_concurrent.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_concurrent.cpp?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_concurrent.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_concurrent.cpp Fri Jan 11 06:38:32 2008
@@ -25,7 +25,7 @@
 #include "interior_pointer.h"
 #include "collection_scheduler.h"
 #include "gc_concurrent.h"
-#include "../gen/gc_for_barrier.h"
+#include "../common/gc_for_barrier.h"
 
 Boolean USE_CONCURRENT_GC           = FALSE;
 Boolean USE_CONCURRENT_ENUMERATION  = FALSE;
@@ -60,16 +60,31 @@
   }
 }
 
+void gc_check_mutator_barrier(GC* gc){
+  lock(gc->mutator_list_lock);    
+
+  Mutator *mutator = gc->mutator_list;
+  while(mutator){
+    wait_mutator_signal(mutator, MUTATOR_ENTER_BARRIER);
+    mutator = mutator->next;
+  }
+
+  unlock(gc->mutator_list_lock);
+}
+
 static void gc_wait_concurrent_mark_finish(GC* gc)
 {
   wait_mark_finish(gc);
   gc_set_barrier_function(WRITE_BARRIER_REM_NIL);
+  mem_fence();
+  gc_check_mutator_barrier(gc);
   gc_set_concurrent_status(gc,GC_CONCURRENT_STATUS_NIL);
 }
 
 void gc_start_concurrent_mark(GC* gc)
 {
   int disable_count;
+  unsigned int num_marker;
   
   if(!try_lock(gc->concurrent_mark_lock) || gc_mark_is_concurrent()) return;
     
@@ -92,6 +107,8 @@
   gc_set_concurrent_status(gc, GC_CONCURRENT_MARK_PHASE);
 
   gc_decide_collection_kind((GC_Gen*)gc, GC_CAUSE_NIL);
+
+  num_marker = gc_decide_marker_number(gc);
   
   /*start concurrent mark*/
 #ifndef USE_MARK_SWEEP_GC
@@ -99,13 +116,16 @@
 #else
   if(gc_concurrent_match_algorithm(OTF_REM_OBJ_SNAPSHOT_ALGO)){
     gc_set_barrier_function(WRITE_BARRIER_REM_OBJ_SNAPSHOT);
-    gc_ms_start_concurrent_mark((GC_MS*)gc, MIN_NUM_MARKERS);
+    gc_check_mutator_barrier(gc);
+    gc_ms_start_concurrent_mark((GC_MS*)gc, num_marker);
   }else if(gc_concurrent_match_algorithm(MOSTLY_CONCURRENT_ALGO)){
     gc_set_barrier_function(WRITE_BARRIER_REM_SOURCE_OBJ);
-    gc_ms_start_most_concurrent_mark((GC_MS*)gc, MIN_NUM_MARKERS);
+    gc_check_mutator_barrier(gc);
+    gc_ms_start_most_concurrent_mark((GC_MS*)gc, num_marker);
   }else if(gc_concurrent_match_algorithm(OTF_REM_NEW_TARGET_ALGO)){  
     gc_set_barrier_function(WRITE_BARRIER_REM_OLD_VAR);
-    gc_ms_start_concurrent_mark((GC_MS*)gc, MIN_NUM_MARKERS);
+    gc_check_mutator_barrier(gc);
+    gc_ms_start_concurrent_mark((GC_MS*)gc, num_marker);
   }
 #endif
 
@@ -294,8 +314,6 @@
 
   vm_reclaim_native_objs();
   gc->in_collection = FALSE;
-
-  gc_reset_collector_state(gc);
   
   if(USE_CONCURRENT_GC && gc_mark_is_concurrent()){
     gc_reset_concurrent_mark(gc);    
@@ -323,5 +341,4 @@
     }
   }
 }
-
 

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_concurrent.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_concurrent.h?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_concurrent.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_concurrent.h Fri Jan 11 06:38:32 2008
@@ -35,10 +35,13 @@
 
   
   ENABLE_COLLECTOR_SWEEP_GLOBAL_CHUNKS = 0x03,
-  DISABLE_COLLECTOR_SWEEP_GLOBAL_CHUNKS = 0x04
-//  /*collector to mutator*/
-//  ENABLE_MUTATOR_ALLOC_BARRIER = 0x03,
-//  DISABLE_MUTATOR_ALLOC_BARRIER = 0x04
+  DISABLE_COLLECTOR_SWEEP_GLOBAL_CHUNKS = 0x04,
+
+  MUTATOR_ENTER_BARRIER = 0x05,
+  MUTATOR_EXIT_BARRIER = 0x06,
+
+  MUTATOR_ENTER_ALLOCATION_MARK = 0x07,
+  MUTATOR_EXIT_ALLOCATION_MARK = 0x08
 };
 
 extern Boolean USE_CONCURRENT_GC;
@@ -78,7 +81,7 @@
 
 inline void gc_mark_unset_concurrent()
 {
-  gc_disenable_alloc_obj_live();
+  gc_disable_alloc_obj_live();
   mark_is_concurrent = FALSE;
 }
 
@@ -125,13 +128,13 @@
 
   gc->gc_concurrent_status = status;
   switch(status){
-    case GC_CONCURRENT_MARK_PHASE:  
-      concurrent_mark_phase = TRUE;
+    case GC_CONCURRENT_MARK_PHASE: 
       gc_mark_set_concurrent();
+      concurrent_mark_phase = TRUE;
       break;
     case GC_CONCURRENT_SWEEP_PHASE:
-      concurrent_sweep_phase = TRUE;
       gc_sweep_set_concurrent();
+      concurrent_sweep_phase = TRUE;
       break;
     default:
       assert(!concurrent_mark_phase && !concurrent_sweep_phase);

Added: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_barrier.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_barrier.cpp?rev=611186&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_barrier.cpp (added)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_barrier.cpp Fri Jan 11 06:38:32 2008
@@ -0,0 +1,231 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Xiao-Feng Li, 2006/10/05
+ */
+
+#include "../gen/gen.h"
+#include "../thread/mutator.h"
+#include "gc_for_barrier.h"
+#include "../mark_sweep/wspace_mark_sweep.h"
+#include "../common/gc_concurrent.h"
+#include "../finalizer_weakref/finalizer_weakref.h"
+
+
+/* All the write barrier interfaces need cleanup */
+
+volatile unsigned int write_barrier_function;
+
+/* The implementations are only temporary */
+static void write_barrier_rem_source_slot(Managed_Object_Handle *p_slot, 
+                      Managed_Object_Handle p_target) 
+{
+  if(p_target >= nos_boundary && p_slot < nos_boundary){
+
+    Mutator *mutator = (Mutator *)gc_get_tls();
+    assert( addr_belongs_to_nos(p_target) && !addr_belongs_to_nos(p_slot)); 
+            
+    mutator_remset_add_entry(mutator, (REF*)p_slot);
+  }
+  return;
+}
+
+static void write_barrier_rem_source_obj(Managed_Object_Handle p_obj_holding_ref)
+{
+  if(obj_need_remember((Partial_Reveal_Object*)p_obj_holding_ref)){
+    Mutator *mutator = (Mutator *)gc_get_tls();
+
+    //FIXME: Release lock.
+    lock(mutator->dirty_set_lock);
+    obj_dirty_in_table((Partial_Reveal_Object *) p_obj_holding_ref);
+    mutator_dirtyset_add_entry(mutator, (Partial_Reveal_Object*)p_obj_holding_ref);
+    unlock(mutator->dirty_set_lock);
+  }
+}
+
+static void gc_object_write_barrier(Managed_Object_Handle p_object) 
+{
+  
+  if( addr_belongs_to_nos(p_object)) return;
+
+  Mutator *mutator = (Mutator *)gc_get_tls();
+  
+  REF* p_slot; 
+  /* scan array object */
+  if (object_is_array((Partial_Reveal_Object*)p_object)) {
+    Partial_Reveal_Object* array = (Partial_Reveal_Object*)p_object;
+    assert(!obj_is_primitive_array(array));
+    
+    int32 array_length = vector_get_length((Vector_Handle) array);
+    for (int i = 0; i < array_length; i++) {
+      p_slot = (REF*)vector_get_element_address_ref((Vector_Handle) array, i);
+      if( read_slot(p_slot) != NULL && addr_belongs_to_nos(read_slot(p_slot))){
+        mutator_remset_add_entry(mutator, p_slot);
+      }
+    }   
+    return;
+  }
+
+  /* scan non-array object */
+  Partial_Reveal_Object* p_obj =  (Partial_Reveal_Object*)p_object;   
+  unsigned int num_refs = object_ref_field_num(p_obj);
+  int *ref_iterator = object_ref_iterator_init(p_obj);
+            
+  for(unsigned int i=0; i<num_refs; i++){
+    p_slot = object_ref_iterator_get(ref_iterator+i, p_obj);        
+    if( addr_belongs_to_nos(read_slot(p_slot))){
+      mutator_remset_add_entry(mutator, p_slot);
+    }
+  }
+
+  return;
+}
+
+
+/*This function is for concurrent mark.*/
+static void write_barrier_rem_obj_snapshot(Managed_Object_Handle p_obj_holding_ref)
+{
+  Mutator *mutator = (Mutator *)gc_get_tls();
+  REF* p_obj_slot; 
+  if(obj_need_take_snapshot((Partial_Reveal_Object*)p_obj_holding_ref)){
+    if (object_is_array((Partial_Reveal_Object*)p_obj_holding_ref)) {
+      Partial_Reveal_Object* array = (Partial_Reveal_Object*)p_obj_holding_ref;
+      assert(!obj_is_primitive_array(array));
+
+      Partial_Reveal_Object* obj_to_snapshot; 
+      
+      int32 array_length = vector_get_length((Vector_Handle) array);
+      for (int i = 0; i < array_length; i++) {
+        p_obj_slot = (REF*)vector_get_element_address_ref((Vector_Handle) array, i);
+        obj_to_snapshot = (Partial_Reveal_Object*)read_slot(p_obj_slot);
+        if (obj_to_snapshot != NULL)  
+          mutator_dirtyset_add_entry(mutator, obj_to_snapshot);
+      }   
+    }else{
+      /* scan non-array object */
+      Partial_Reveal_Object* p_obj =  (Partial_Reveal_Object*)p_obj_holding_ref;   
+      unsigned int num_refs = object_ref_field_num(p_obj);
+      int *ref_iterator = object_ref_iterator_init(p_obj);
+      
+      Partial_Reveal_Object* obj_to_snapshot; 
+
+      for(unsigned int i=0; i<num_refs; i++){
+        p_obj_slot = object_ref_iterator_get(ref_iterator+i, p_obj);        
+        obj_to_snapshot = (Partial_Reveal_Object*)read_slot(p_obj_slot);
+        if (obj_to_snapshot != NULL)  
+          mutator_dirtyset_add_entry(mutator, obj_to_snapshot);
+      }
+
+      if(is_reference_obj(p_obj)){
+        REF* p_referent_field = obj_get_referent_field(p_obj);
+        obj_to_snapshot = (Partial_Reveal_Object*)read_slot(p_referent_field);
+        if (obj_to_snapshot != NULL)  
+          mutator_dirtyset_add_entry(mutator, obj_to_snapshot);
+      }
+    }
+    obj_mark_black_in_table((Partial_Reveal_Object *) p_obj_holding_ref);
+    obj_dirty_in_table((Partial_Reveal_Object *) p_obj_holding_ref);
+  }
+}
+
+static void write_barrier_rem_slot_oldvar(Managed_Object_Handle* p_slot)
+{
+  Mutator *mutator = (Mutator *)gc_get_tls();  
+  REF* p_obj_slot = (REF*) p_slot ;
+  Partial_Reveal_Object* p_obj = (Partial_Reveal_Object*)read_slot(p_obj_slot);
+  if(p_obj && obj_need_remember_oldvar(p_obj)){
+    mutator_dirtyset_add_entry(mutator, p_obj);
+  }
+}
+
+//===========================================
+
+/* The following routines were supposed to be the only way to alter any value in gc heap. */
+void gc_heap_write_ref (Managed_Object_Handle p_obj_holding_ref, unsigned offset, Managed_Object_Handle p_target) 
+{  assert(0); }
+
+void gc_heap_wrote_object (Managed_Object_Handle p_obj_written)
+{
+  /*Concurrent Mark: Since object clone and array copy do not modify object slots, 
+      we treat it as an new object. It has already been marked when dest object was created.
+      We use WRITE_BARRIER_REM_SOURCE_OBJ function here to debug.
+    */  
+  Mutator *mutator = (Mutator *)gc_get_tls();  
+  mutator_post_signal(mutator,MUTATOR_ENTER_BARRIER);
+
+  if(WRITE_BARRIER_REM_SOURCE_OBJ == write_barrier_function){
+    lock(mutator->dirty_set_lock);
+    
+    obj_dirty_in_table((Partial_Reveal_Object *) p_obj_written);
+    mutator_dirtyset_add_entry(mutator, (Partial_Reveal_Object*)p_obj_written);
+    
+    unlock(mutator->dirty_set_lock);
+  }
+  mutator_post_signal(mutator,MUTATOR_EXIT_BARRIER);
+
+  if( !gc_is_gen_mode() ) return;
+  if( object_has_ref_field((Partial_Reveal_Object*)p_obj_written)){
+    /* for array copy and object clone */
+    gc_object_write_barrier(p_obj_written); 
+  }
+}
+
+/* FIXME:: this is not the right interface for write barrier */
+void gc_heap_slot_write_ref (Managed_Object_Handle p_obj_holding_ref,Managed_Object_Handle *p_slot, Managed_Object_Handle p_target)
+{ 
+  Mutator *mutator = (Mutator *)gc_get_tls();  
+  mutator_post_signal(mutator,MUTATOR_ENTER_BARRIER);
+
+  switch(write_barrier_function){
+    case WRITE_BARRIER_REM_NIL:
+      *p_slot = p_target;
+      break;
+    case WRITE_BARRIER_REM_SOURCE_REF:
+      *p_slot = p_target;
+      write_barrier_rem_source_slot(p_slot, p_target); 
+      break;      
+    case WRITE_BARRIER_REM_SOURCE_OBJ:
+      *p_slot = p_target;
+      write_barrier_rem_source_obj(p_obj_holding_ref);
+      break;
+    case WRITE_BARRIER_REM_OBJ_SNAPSHOT:
+      write_barrier_rem_obj_snapshot(p_obj_holding_ref);
+      *p_slot = p_target;
+      break;
+    case WRITE_BARRIER_REM_OLD_VAR:
+      write_barrier_rem_slot_oldvar(p_slot);      
+      *p_slot = p_target;
+      break;
+    default:
+      assert(0);
+      return;
+  }
+
+  mutator_post_signal(mutator,MUTATOR_EXIT_BARRIER);
+  return;
+}
+
+/* this is used for global object update, e.g., strings. */
+void gc_heap_write_global_slot(Managed_Object_Handle *p_slot,Managed_Object_Handle p_target)
+{
+  /*Concurrent Mark & Generational Mode: 
+      Global objects are roots. After root set enumeration, this objects will be touched by GC. No barrier here.
+    */
+
+  *p_slot = p_target;
+}

Propchange: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_barrier.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_barrier.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_barrier.h?rev=611186&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_barrier.h (added)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_barrier.h Fri Jan 11 06:38:32 2008
@@ -0,0 +1,43 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Xiao-Feng Li, 2006/10/05
+ */
+
+#ifndef _GC_FOR_BARRIER_H_
+#define _GC_FOR_BARRIER_H_
+
+#include "../jni/java_support.h"
+
+extern volatile unsigned int write_barrier_function;
+
+enum Write_Barrier_Function{
+  WRITE_BARRIER_REM_NIL           = 0x00,
+  WRITE_BARRIER_REM_SOURCE_OBJ    = 0x01,
+  WRITE_BARRIER_REM_SOURCE_REF    = 0x02,
+  WRITE_BARRIER_REM_OLD_VAR       = 0x03,
+  WRITE_BARRIER_REM_NEW_VAR       = 0x04,
+  WRITE_BARRIER_REM_OBJ_SNAPSHOT  = 0x05
+};
+
+inline void gc_set_barrier_function(unsigned int wb_function)
+{
+  write_barrier_function = wb_function;
+}
+#endif /* _GC_FOR_BARRIER_H_ */
+

Propchange: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_barrier.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_class.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_class.h?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_class.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_class.h Fri Jan 11 06:38:32 2008
@@ -67,6 +67,8 @@
 
 #define OBJ_DIRTY_BIT 0x20
 
+#define OBJ_AGE_BIT 0x40
+
 #ifdef POINTER64 // Like in VM
   #define COMPRESS_VTABLE
 #endif
@@ -310,7 +312,6 @@
 }
 
 #endif //#ifndef _GC_TYPES_H_
-
 
 
 

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_vm.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_vm.cpp?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_vm.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_for_vm.cpp Fri Jan 11 06:38:32 2008
@@ -27,6 +27,7 @@
 
 #include "../gen/gen.h"
 #include "../mark_sweep/gc_ms.h"
+#include "../move_compact/gc_mc.h"
 #include "interior_pointer.h"
 #include "../thread/marker.h"
 #include "../thread/collector.h"
@@ -443,4 +444,5 @@
 {
   return address_belongs_to_gc_heap(p_obj, p_global_gc);  
 }
+
 

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_metadata.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_metadata.cpp?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_metadata.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_metadata.cpp Fri Jan 11 06:38:32 2008
@@ -25,6 +25,7 @@
 #include "gc_block.h"
 #include "compressed_ref.h"
 #include "../utils/sync_stack.h"
+#include "../gen/gen.h"
 
 #define GC_METADATA_SIZE_BYTES (1*MB)
 #define GC_METADATA_EXTEND_SIZE_BYTES (1*MB)
@@ -379,7 +380,8 @@
 void gc_clear_remset(GC* gc)
 {
   assert(gc->root_set != NULL);
-
+  /* rootset pool has some entries that are actually remset, because all the remsets are put into rootset pool 
+     before the collection. gc->root_set is a pointer pointing to the boundary between remset and rootset in the pool */
   Pool* pool = gc_metadata.gc_rootset_pool;    
   Vector_Block* rem_set = pool_get_entry(pool);
   while(rem_set != gc->root_set){
@@ -391,6 +393,25 @@
   assert(rem_set == gc->root_set);
   /* put back root set */
   pool_put_entry(pool, rem_set);
+  
+  /* put back last remset block of each collector (saved in the minor collection before fallback) */  
+  unsigned int num_active_collectors = gc->num_active_collectors;
+  for(unsigned int i=0; i<num_active_collectors; i++)
+  {
+    Collector* collector = gc->collectors[i];
+    assert(collector->rem_set != NULL);
+    pool_put_entry(gc_metadata.collector_remset_pool, collector->rem_set);
+    collector->rem_set = NULL;
+  }
+  
+  /* cleanup remset pool */  
+  pool = gc_metadata.collector_remset_pool;  
+  rem_set = pool_get_entry(pool);
+  while(rem_set){
+    vector_block_clear(rem_set);
+    pool_put_entry(gc_metadata.free_set_pool, rem_set);
+    rem_set = pool_get_entry(pool);
+  }
     
   return;
 } 
@@ -510,6 +531,4 @@
 
 void free_set_pool_put_entry(Vector_Block* block, GC_Metadata *metadata)
 { pool_put_entry(metadata->free_set_pool, block); }
-
-
 

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_metadata.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_metadata.h?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_metadata.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_metadata.h Fri Jan 11 06:38:32 2008
@@ -63,16 +63,16 @@
 void gc_reset_rootset(GC* gc);
 void gc_clear_rootset(GC* gc);
 void gc_fix_rootset(Collector* collector, Boolean double_fix);
+
 void gc_clear_remset(GC* gc);
+
+void gc_prepare_dirty_set(GC* gc);
 void gc_reset_dirty_set(GC* gc);
+void gc_clear_dirty_set(GC* gc);
 
 void gc_identify_dead_weak_roots(GC *gc);
 void gc_update_weak_roots(GC *gc, Boolean double_fix);
 
-void gc_clear_remset(GC* gc);
-void gc_clear_dirty_set(GC* gc);
-
-void gc_prepare_dirty_set(GC* gc);
 
 inline void  gc_task_pool_clear(Pool* task_pool)
 {

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_platform.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_platform.h?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_platform.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_platform.h Fri Jan 11 06:38:32 2008
@@ -118,7 +118,7 @@
 
 inline int vm_thread_is_suspend_enable()
 {
-  return hythread_is_suspend_enabled();
+  return (int)hythread_is_suspend_enabled();
 }
 
 inline void *atomic_casptr(volatile void **mem, void *with, const void *cmp) 
@@ -128,6 +128,7 @@
                                         POINTER_SIZE_INT swap, 
                                         POINTER_SIZE_INT cmp)
 {
+  // we can't use apr_atomic_casptr, which can't work correctly in 64bit machine. 
 #ifdef POINTER64
   return port_atomic_cas64(mem, swap, cmp);
 #else
@@ -135,26 +136,20 @@
 #endif
 }
 
-inline uint32 atomic_cas32(volatile apr_uint32_t *mem,
+inline uint32 atomic_cas32(volatile unsigned int *mem,
                                            apr_uint32_t swap,
                                            apr_uint32_t cmp) 
 {  return (uint32)apr_atomic_cas32(mem, swap, cmp); }
 
-inline uint32 atomic_inc32(volatile apr_uint32_t *mem)
+inline uint32 atomic_inc32(volatile unsigned int *mem)
 {  return (uint32)apr_atomic_inc32(mem); }
 
-inline uint32 atomic_dec32(volatile apr_uint32_t *mem)
+inline uint32 atomic_dec32(volatile unsigned int  *mem)
 {  return (uint32)apr_atomic_dec32(mem); }
 
-inline uint32 atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val) 
+inline uint32 atomic_add32(volatile unsigned int  *mem, unsigned int  val) 
 {  return (uint32)apr_atomic_add32(mem, val); }
 
-inline Boolean pool_create(apr_pool_t **newpool, apr_pool_t *parent) 
-{  return (Boolean)apr_pool_create(newpool, parent);}
-
-inline void pool_destroy(apr_pool_t *p) 
-{  apr_pool_destroy(p); }
-
 #ifndef _WINDOWS_
 #include <sys/mman.h>
 #endif
@@ -268,6 +263,12 @@
 #endif /* ifdef _WINDOWS_ else */
 
   return result;
+}
+
+inline void mem_fence()
+{
+  //FIXME: enable mem fence.
+  //apr_memory_rw_barrier(); 
 }
 
 inline int64 time_now() 

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_space.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_space.h?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_space.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/gc_space.h Fri Jan 11 06:38:32 2008
@@ -125,8 +125,8 @@
 }Blocked_Space;
 
 inline Boolean blocked_space_has_free_block(Blocked_Space *space){ return space->free_block_idx <= space->ceiling_block_idx; }
-inline unsigned int blocked_space_free_mem_size(Blocked_Space *space){ return GC_BLOCK_SIZE_BYTES * (space->ceiling_block_idx - space->free_block_idx + 1);  }
-inline Boolean blocked_space_used_mem_size(Blocked_Space *space){ return GC_BLOCK_SIZE_BYTES * (space->free_block_idx - space->first_block_idx); }
+inline unsigned int blocked_space_free_mem_size(Blocked_Space *space){ return (space->ceiling_block_idx - space->free_block_idx + 1) << GC_BLOCK_SHIFT_COUNT;  }
+inline Boolean blocked_space_used_mem_size(Blocked_Space *space){ return (space->free_block_idx - space->first_block_idx) << GC_BLOCK_SHIFT_COUNT; }
 
 void space_init_blocks(Blocked_Space* space);
 void space_desturct_blocks(Blocked_Space* space);
@@ -138,5 +138,9 @@
 void blocked_space_block_iterator_init_free(Blocked_Space *space);
 Block_Header *blocked_space_block_iterator_get(Blocked_Space *space);
 Block_Header *blocked_space_block_iterator_next(Blocked_Space *space);
+
+#ifndef STATIC_NOS_MAPPING
+void blocked_space_adjust(Blocked_Space* space, void* new_space_start, POINTER_SIZE_INT new_space_size);
+#endif
 
 #endif //#ifndef _GC_SPACE_H_

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/interior_pointer.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/interior_pointer.cpp?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/interior_pointer.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/interior_pointer.cpp Fri Jan 11 06:38:32 2008
@@ -79,7 +79,7 @@
     void** root_slot = entry_traverser->slot;
     Partial_Reveal_Object* root_base = (Partial_Reveal_Object*)entry_traverser->base;
     unsigned int root_offset = entry_traverser->offset;
-    void *new_slot_contents = (void *)((Byte*)root_base + root_offset);	
+    void *new_slot_contents = (void *)((Byte*)root_base + root_offset);  
     *root_slot = new_slot_contents;
   }
   //can not reset the table here, for the rootset may be updated multi times
@@ -90,6 +90,7 @@
   interior_pointer_num_count = 0;
   //this function is for the case of out of memory which need to call update_rootset_interior_pointer multi-times
 }
+
 
 
 

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/mark_scan_pool.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/mark_scan_pool.cpp?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/mark_scan_pool.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/mark_scan_pool.cpp Fri Jan 11 06:38:32 2008
@@ -45,6 +45,7 @@
 static FORCE_INLINE void scan_object(Collector* collector, Partial_Reveal_Object *p_obj)
 {
   vm_notify_obj_alive( (void *)p_obj);
+  
   assert((((POINTER_SIZE_INT)p_obj) % GC_OBJECT_ALIGNMENT) == 0);
   
   Partial_Reveal_VTable *vtable = decode_vt(obj_get_vt(p_obj));

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/object_status.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/object_status.h?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/object_status.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/object_status.h Fri Jan 11 06:38:32 2008
@@ -20,6 +20,7 @@
 
 #include "../gen/gen.h"
 #include "../mark_sweep/gc_ms.h"
+#include "../move_compact/gc_mc.h"
 #include "../mark_sweep/wspace_mark_sweep.h"
 
 
@@ -74,7 +75,7 @@
 #endif
 
 #ifdef USE_UNIQUE_MOVE_COMPACT_GC
-	return obj_is_dead_in_move_compact_no_los_gc(p_obj);
+  return obj_is_dead_in_move_compact_no_los_gc(p_obj);
 #endif
 
   if(gc_match_kind(gc, MINOR_COLLECTION)){

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/space_tuner.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/space_tuner.cpp?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/space_tuner.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/common/space_tuner.cpp Fri Jan 11 06:38:32 2008
@@ -538,4 +538,3 @@
 }
 
 
-

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/finalizer_weakref/finalizer_weakref.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/finalizer_weakref/finalizer_weakref.cpp?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/finalizer_weakref/finalizer_weakref.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/finalizer_weakref/finalizer_weakref.cpp Fri Jan 11 06:38:32 2008
@@ -814,4 +814,3 @@
 
 
 
-

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/finalizer_weakref/finalizer_weakref.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/finalizer_weakref/finalizer_weakref.h?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/finalizer_weakref/finalizer_weakref.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/finalizer_weakref/finalizer_weakref.h Fri Jan 11 06:38:32 2008
@@ -100,6 +100,14 @@
   scan_slot(collector, p_referent_field);
 }
 
+inline Boolean is_reference_obj(Partial_Reveal_Object *p_obj)
+{
+  WeakReferenceType type = special_reference_type(p_obj);
+  if(type == NOT_REFERENCE)
+    return FALSE;
+  else
+    return TRUE;
+}
 
 extern void gc_update_weakref_ignore_finref(GC *gc);
 extern void collector_identify_finref(Collector *collector);

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/finalizer_weakref/finalizer_weakref_metadata.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/finalizer_weakref/finalizer_weakref_metadata.cpp?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/finalizer_weakref/finalizer_weakref_metadata.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/finalizer_weakref/finalizer_weakref_metadata.cpp Fri Jan 11 06:38:32 2008
@@ -442,4 +442,3 @@
 }
 
 
-

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen.cpp?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen.cpp Fri Jan 11 06:38:32 2008
@@ -44,7 +44,7 @@
 
 /* should clean up */
 unsigned int MINOR_ALGO = 0;
-static unsigned int MAJOR_ALGO = 0;
+unsigned int MAJOR_ALGO = 0;
 
 Boolean GEN_NONGEN_SWITCH = FALSE;
 
@@ -170,10 +170,15 @@
   }
   
   if(reserved_base == NULL){
-    Boolean max_size_reduced = FALSE;
+    if(max_heap_size < min_heap_size){
+      DIE2("gc.base","Max heap size is smaller than min heap size. Please choose other values.");
+      exit(0);
+    }
+
+    unsigned int max_size_reduced = 0;
     reserved_base = vm_reserve_mem(NULL, max_heap_size + SPACE_ALLOC_UNIT);
     while( !reserved_base ){
-      max_size_reduced = TRUE;
+      max_size_reduced += SPACE_ALLOC_UNIT;
       max_heap_size -= SPACE_ALLOC_UNIT;
       reserved_base = vm_reserve_mem(NULL, max_heap_size + SPACE_ALLOC_UNIT);
     }
@@ -181,13 +186,10 @@
     physical_start = reserved_base;
     
     if(max_size_reduced){
-      WARN2("gc.base","Max heap size: can't be reserved, reduced to "<< max_heap_size/MB<<" MB according to virtual memory limitation.");
-    }
-    
-    if(max_heap_size < min_heap_size){
-      DIE2("gc.base","Heap size: invalid, please reimput a smaller \"ms\" paramenter!");
+      DIE2("gc.base","Max heap size: can't be reserved. The max size can be reserved is "<< max_heap_size/MB<<" MB. ");
       exit(0);
     }
+    
     reserved_base = (void*)round_up_to_size((POINTER_SIZE_INT)reserved_base, SPACE_ALLOC_UNIT);
     assert(!((POINTER_SIZE_INT)reserved_base % SPACE_ALLOC_UNIT));
   }
@@ -300,7 +302,7 @@
 void gc_nos_initialize(GC_Gen *gc, void *start, POINTER_SIZE_INT nos_size, POINTER_SIZE_INT commit_size)
 {
   Space *nos;
-  if(MINOR_ALGO == MINOR_NONGEN_SEMISPACE_POOL){
+  if(MINOR_ALGO == MINOR_NONGEN_SEMISPACE_POOL || MINOR_ALGO == MINOR_GEN_SEMISPACE_POOL){
     nos = (Space*)sspace_initialize((GC*)gc, start, nos_size, commit_size);
     nos_alloc = sspace_alloc;
   }else{
@@ -414,6 +416,10 @@
       MINOR_ALGO = MINOR_NONGEN_SEMISPACE_POOL;
       gc_disable_gen_mode();
     
+    }else if(!strcmp(minor_algo, "MINOR_GEN_SEMISPACE_POOL")){
+      MINOR_ALGO = MINOR_GEN_SEMISPACE_POOL;
+      gc_enable_gen_mode();
+
     }else {
       WARN2("gc.base","\nWarning: GC algorithm setting incorrect. Will use default value.\n");
     
@@ -448,7 +454,7 @@
 static Boolean nos_alloc_block(Space* space, Allocator* allocator)
 {
   Boolean result;
-  if(MINOR_ALGO == MINOR_NONGEN_SEMISPACE_POOL)
+  if(MINOR_ALGO == MINOR_NONGEN_SEMISPACE_POOL || MINOR_ALGO == MINOR_GEN_SEMISPACE_POOL)
     result = sspace_alloc_block((Sspace*)space, allocator); 
   else
     result = fspace_alloc_block((Fspace*)space, allocator);   
@@ -479,11 +485,12 @@
 
 static void gc_gen_adjust_heap_size(GC_Gen* gc)
 {
-  if(gc_match_kind((GC*)gc, MINOR_COLLECTION)) return;
+  assert(gc_match_kind((GC*)gc, MAJOR_COLLECTION));
+  
   if(gc->committed_heap_size == max_heap_size_bytes - LOS_HEAD_RESERVE_FOR_HEAP_NULL) return;
   
   Mspace* mos = (Mspace*)gc->mos;
-  Fspace* nos = (Fspace*)gc->nos;
+  Blocked_Space* nos = (Blocked_Space*)gc->nos;
   Lspace* los = (Lspace*)gc->los;
   /* We can not tolerate gc->survive_ratio be greater than threshold twice continuously.
    * Or, we must adjust heap size
@@ -583,7 +590,7 @@
 
 static inline void nos_collection(Space *nos)
 { 
-  if(MINOR_ALGO == MINOR_NONGEN_SEMISPACE_POOL)
+  if(MINOR_ALGO == MINOR_NONGEN_SEMISPACE_POOL || MINOR_ALGO == MINOR_GEN_SEMISPACE_POOL)
     sspace_collection((Sspace*)nos); 
   else
     fspace_collection((Fspace*)nos); 
@@ -605,17 +612,18 @@
 
 static void gc_gen_update_space_info_before_gc(GC_Gen *gc)
 {
-  Fspace *nos = (Fspace*)gc->nos;
-  Mspace *mos = (Mspace*)gc->mos;
+  Blocked_Space *nos = (Blocked_Space *)gc->nos;
+  Blocked_Space *mos = (Blocked_Space *)gc->mos;
   Lspace *los = (Lspace*)gc->los;
   
   /* Update before every GC to avoid the atomic operation in every fspace_alloc_block */
-  assert( nos->free_block_idx >= nos->first_block_idx );
-  nos->num_used_blocks = nos->free_block_idx - nos->first_block_idx;
-  nos->last_alloced_size = GC_BLOCK_SIZE_BYTES * nos->num_used_blocks;
+  unsigned int nos_used_size = nos_used_space_size((Space*)nos); 
+  assert(nos_used_size >= (nos->num_used_blocks << GC_BLOCK_SHIFT_COUNT));
+  nos->last_alloced_size = nos_used_size - (nos->num_used_blocks << GC_BLOCK_SHIFT_COUNT);
+  nos->num_used_blocks = nos_used_size >> GC_BLOCK_SHIFT_COUNT;
   nos->accumu_alloced_size += nos->last_alloced_size;
   
-  mos->num_used_blocks = mos->free_block_idx - mos->first_block_idx;
+  mos->num_used_blocks = mos_used_space_size((Space*)mos)>> GC_BLOCK_SHIFT_COUNT;
   
   if(los){
     assert(MAJOR_ALGO != MAJOR_MARK_SWEEP);
@@ -659,7 +667,7 @@
  
 static void nos_reset_after_collection(Space *nos)
 {
-  if(MINOR_ALGO == MINOR_NONGEN_SEMISPACE_POOL)
+  if(MINOR_ALGO == MINOR_NONGEN_SEMISPACE_POOL || MINOR_ALGO == MINOR_GEN_SEMISPACE_POOL)
     sspace_reset_after_collection((Sspace*)nos);
   else
     fspace_reset_after_collection((Fspace*)nos);
@@ -667,7 +675,7 @@
 
 static void nos_prepare_for_collection(Space *nos)
 {
-  if(MINOR_ALGO == MINOR_NONGEN_SEMISPACE_POOL)
+  if(MINOR_ALGO == MINOR_NONGEN_SEMISPACE_POOL || MINOR_ALGO == MINOR_GEN_SEMISPACE_POOL)
     sspace_prepare_for_collection((Sspace*)nos);
 }
 
@@ -768,7 +776,8 @@
     
     INFO2("gc.process", "GC: Minor collection failed, transform to fallback collection ...");
     
-    if(gc_is_gen_mode()) gc_clear_remset((GC*)gc);
+    if(gc_is_gen_mode()) 
+      gc_clear_remset((GC*)gc);
     
     /* runout mos in minor collection */
     if(MAJOR_ALGO != MAJOR_MARK_SWEEP){
@@ -822,14 +831,18 @@
     gc_verify_heap((GC*)gc, FALSE);
   
   assert(MAJOR_ALGO == MAJOR_MARK_SWEEP || !los->move_object);
+
+  int64 pause_time = time_now() - gc_start_time;
+  gc->time_collections += pause_time;
   
-  if(MAJOR_ALGO != MAJOR_MARK_SWEEP && MINOR_ALGO != MINOR_NONGEN_SEMISPACE_POOL){
-    gc_gen_adjust_heap_size(gc);
+  if(MAJOR_ALGO != MAJOR_MARK_SWEEP){ /* adaptations here */
     
-    int64 pause_time = time_now() - gc_start_time;
-    gc->time_collections += pause_time;
-    gc_gen_adapt(gc, pause_time);
-    gc_space_tuner_reset((GC*)gc);
+    if(gc_match_kind((GC*)gc, MAJOR_COLLECTION))
+      gc_gen_adjust_heap_size(gc);  /* adjust committed GC heap size */
+      
+    gc_gen_adapt(gc, pause_time); /* 1. decide next collection kind; 2. adjust nos_boundary */
+    
+    gc_space_tuner_reset((GC*)gc); /* related to los_boundary adjustment */
   }
   
   gc_gen_update_space_info_after_gc(gc);
@@ -851,8 +864,8 @@
   bool cont = true;   
   while (mutator) {
     Block_Header* block = (Block_Header*)mutator->alloc_block;
-  	if(block != NULL) block->free = mutator->free;
-  	mutator = mutator->next;
+    if(block != NULL) block->free = mutator->free;
+    mutator = mutator->next;
   }
 
   Blocked_Space *mspace = (Blocked_Space*)gc->mos;
@@ -878,16 +891,16 @@
   curr_block = (Block_Header*)fspace->blocks;
   space_end = (Block_Header*)&fspace->blocks[fspace->free_block_idx - fspace->first_block_idx];
   while(curr_block < space_end) {
-   	POINTER_SIZE_INT p_obj = (POINTER_SIZE_INT)curr_block->base;
+    POINTER_SIZE_INT p_obj = (POINTER_SIZE_INT)curr_block->base;
     POINTER_SIZE_INT block_end = (POINTER_SIZE_INT)curr_block->free;
     while(p_obj < block_end){
       cont = vm_iterate_object((Managed_Object_Handle)p_obj);
       if (!cont) return;
       p_obj = p_obj + vm_object_size((Partial_Reveal_Object *)p_obj);
     }
-    	curr_block = curr_block->next;
-      if(curr_block == NULL) break;
-    }
+    curr_block = curr_block->next;
+    if(curr_block == NULL) break;
+  }
 
   Lspace *lspace = (Lspace*)gc->los;
   POINTER_SIZE_INT lspace_obj = (POINTER_SIZE_INT)lspace->heap_start;
@@ -962,8 +975,18 @@
   INFO2("gc.space","GC: Heap info after GC["<<gc->num_collections<<"]:"
     <<"\nGC: Heap size: "<<verbose_print_size(gc->committed_heap_size)<<", free size:"<<verbose_print_size(gc_gen_free_memory_size(gc))
     <<"\nGC: LOS size: "<<verbose_print_size(gc->los->committed_heap_size)<<", free size:"<<verbose_print_size(lspace_free_memory_size((Lspace*)gc->los))
-    <<"\nGC: MOS size: "<<verbose_print_size(gc->mos->committed_heap_size)<<", free size:"<<verbose_print_size(blocked_space_free_mem_size((Blocked_Space*)gc->mos))
-    <<"\nGC: NOS size: "<<verbose_print_size(gc->nos->committed_heap_size)<<", free size:"<<verbose_print_size(blocked_space_free_mem_size((Blocked_Space*)gc->nos))<<"\n");
+    <<"\nGC: MOS size: "<<verbose_print_size(gc->mos->committed_heap_size)<<", free size:"<<verbose_print_size(blocked_space_free_mem_size((Blocked_Space*)gc->mos)) << "\n");
+
+  if(MINOR_ALGO == MINOR_NONGEN_SEMISPACE_POOL || MINOR_ALGO == MINOR_GEN_SEMISPACE_POOL){
+    INFO2("gc.space", 
+    	"GC: NOS size: "<<verbose_print_size(gc->nos->committed_heap_size)
+    	<<", tospace size:"<<verbose_print_size(sspace_tospace_size((Sspace*)gc->nos))
+    	<<", survivor area size:"<<verbose_print_size(sspace_survivor_area_size((Sspace*)gc->nos)) << "\n");
+
+  }else{
+    INFO2("gc.space", 
+    	"GC: NOS size: "<<verbose_print_size(gc->nos->committed_heap_size)<<", free size:"<<verbose_print_size(blocked_space_free_mem_size((Blocked_Space*)gc->nos))<<"\n");
+  }
 }
 
 inline void gc_gen_init_verbose(GC_Gen *gc)
@@ -975,7 +998,7 @@
     <<"\ninitial num collectors: "<<gc->num_collectors
     <<"\ninitial nos size: "<<verbose_print_size(gc->nos->committed_heap_size)
     <<"\nnos collection algo: "
-    <<((gc->nos->collect_algorithm==MINOR_NONGEN_FORWARD_POOL)?"nongen forward":"gen forward")
+    <<((gc->nos->collect_algorithm==MINOR_NONGEN_SEMISPACE_POOL || gc->nos->collect_algorithm==MINOR_GEN_SEMISPACE_POOL)?"semi space":"partial forward")
     <<"\ninitial mos size: "<<verbose_print_size(gc->mos->committed_heap_size)
     <<"\nmos collection algo: "
     <<((gc->mos->collect_algorithm==MAJOR_COMPACT_MOVE)?"move compact":"slide compact")
@@ -1035,5 +1058,4 @@
     STD_FREE(collector->backup_allocator);  
   }
 }
-
 

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen.h?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen.h Fri Jan 11 06:38:32 2008
@@ -25,14 +25,7 @@
 
 #include "../common/gc_common.h"
 #include "../thread/gc_thread.h"
-
-#include "../trace_forward/fspace.h"
-#include "../semi_space/sspace.h"
-
-#include "../mark_compact/mspace.h"
-#include "../los/lspace.h"
-
-#include "../mark_sweep/wspace.h"
+#include "../common/gc_for_barrier.h"
 
 #include "../finalizer_weakref/finalizer_weakref_metadata.h"
 
@@ -40,12 +33,33 @@
 struct GC_Gen_Stats;
 #endif
 
-enum Write_Barrier_Kind{
-  WRITE_BARRIER_NIL,  
-  WRITE_BARRIER_SLOT,  
-  WRITE_BARRIER_OBJECT,
-  WRITE_BARRIER_UPDATE      
-}; 
+extern Boolean gen_mode;
+
+inline Boolean gc_is_gen_mode()
+{  return gen_mode; }
+
+inline void gc_enable_gen_mode()
+{  
+  gen_mode = TRUE;
+  gc_set_barrier_function(WRITE_BARRIER_REM_SOURCE_REF);
+  HelperClass_set_GenMode(TRUE);
+}
+
+inline void gc_disable_gen_mode()
+{  
+  gen_mode = FALSE; 
+  gc_set_barrier_function(WRITE_BARRIER_REM_NIL);
+  HelperClass_set_GenMode(FALSE);
+}
+
+inline void gc_set_gen_mode(Boolean status)
+{
+  gen_mode = status; 
+  if(gen_mode) 
+    gc_set_barrier_function(WRITE_BARRIER_REM_SOURCE_REF);
+  HelperClass_set_GenMode(status);   
+}
+
 
 /* some globals */
 extern POINTER_SIZE_INT NOS_SIZE;
@@ -58,6 +72,12 @@
 extern POINTER_SIZE_INT min_nos_size_bytes;
 extern POINTER_SIZE_INT max_nos_size_bytes;
 
+#include "../trace_forward/fspace.h"
+#include "../semi_space/sspace.h"
+#include "../mark_compact/mspace.h"
+#include "../los/lspace.h"
+#include "../mark_sweep/wspace.h"
+
 struct Gen_Mode_Adaptor;
 
 typedef struct GC_Gen {
@@ -111,6 +131,7 @@
   SpinLock concurrent_mark_lock;
   SpinLock enumerate_rootset_lock;
   SpinLock concurrent_sweep_lock;
+  SpinLock collection_scheduler_lock;
 
   
   /* system info */
@@ -209,8 +230,16 @@
 
 extern Boolean GEN_NONGEN_SWITCH ;
 
-#endif /* ifndef _GC_GEN_H_ */
+POINTER_SIZE_INT mos_free_space_size(Space* mos);
+POINTER_SIZE_INT nos_free_space_size(Space* nos);
+POINTER_SIZE_INT mos_used_space_size(Space* mos);
+POINTER_SIZE_INT nos_used_space_size(Space* nos);
 
+#ifndef STATIC_NOS_MAPPING
+void* nos_space_adjust(Space* space, void* new_nos_boundary, POINTER_SIZE_INT new_nos_size);
+#endif
+
+#endif /* ifndef _GC_GEN_H_ */
 
 
 

Modified: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen_adapt.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen_adapt.cpp?rev=611186&r1=611185&r2=611186&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen_adapt.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/gen/gen_adapt.cpp Fri Jan 11 06:38:32 2008
@@ -25,10 +25,8 @@
 
 #define NOS_COPY_RESERVE_DELTA (GC_BLOCK_SIZE_BYTES<<1)
 /*Tune this number in case that MOS could be too small, so as to avoid or put off fall back.*/
-#define MOS_EXTRA_REMAIN_SIZE_TO_ANTI_FALLBACK (36*MB)
-
-struct Mspace;
-void mspace_set_expected_threshold_ratio(Mspace* mspace, float threshold_ratio);
+POINTER_SIZE_INT MOS_RESERVE_SIZE;
+POINTER_SIZE_INT DEFAULT_MOS_RESERVE_SIZE = 36*MB;
 
 static float Tslow = 0.0f;
 static POINTER_SIZE_INT SMax = 0;
@@ -97,18 +95,18 @@
 {
   if(GEN_NONGEN_SWITCH == FALSE) return;
   
-  Blocked_Space* fspace = (Blocked_Space*)gc->nos;
-  Blocked_Space* mspace = (Blocked_Space*)gc->mos;
+  Blocked_Space* nos = (Blocked_Space*)gc->nos;
+  Blocked_Space* mos = (Blocked_Space*)gc->mos;
   Gen_Mode_Adaptor* gen_mode_adaptor = gc->gen_mode_adaptor;
 
-  POINTER_SIZE_INT mos_free_size = blocked_space_free_mem_size(mspace);
-  POINTER_SIZE_INT nos_free_size = blocked_space_free_mem_size(fspace);
+  POINTER_SIZE_INT mos_free_size = blocked_space_free_mem_size(mos);
+  POINTER_SIZE_INT nos_free_size = blocked_space_free_mem_size(nos);
   POINTER_SIZE_INT total_free_size = mos_free_size  + nos_free_size;
   
   if(gc_match_kind((GC*)gc, MAJOR_COLLECTION)) {
     assert(!gc_is_gen_mode());
     
-    if(gen_mode_adaptor->major_survive_ratio_threshold != 0 && mspace->survive_ratio > gen_mode_adaptor->major_survive_ratio_threshold){    
+    if(gen_mode_adaptor->major_survive_ratio_threshold != 0 && mos->survive_ratio > gen_mode_adaptor->major_survive_ratio_threshold){    
       if(gen_mode_adaptor->major_repeat_count > MAX_MAJOR_REPEAT_COUNT ){
         gc->force_gen_mode = TRUE;
         gc_enable_gen_mode();
@@ -144,7 +142,7 @@
 
     if(gen_mode_adaptor->nongen_minor_throughput <=  gen_mode_adaptor->gen_minor_throughput ){
       if( gc->last_collect_kind != MINOR_COLLECTION ){
-        gen_mode_adaptor->major_survive_ratio_threshold = mspace->survive_ratio;
+        gen_mode_adaptor->major_survive_ratio_threshold = mos->survive_ratio;
       }else if( !gc->force_gen_mode ){
         gc->force_gen_mode = TRUE;
         gen_mode_adaptor->gen_mode_trial_count = MAX_INT32;        
@@ -186,90 +184,102 @@
   return;
 }
 
-void mspace_set_expected_threshold_ratio(Mspace* mspace, float threshold_ratio);
+struct Mspace;
+void mspace_set_expected_threshold_ratio(Mspace* mos, float threshold_ratio);
 
 static void gc_decide_next_collect(GC_Gen* gc, int64 pause_time)
 {
-  Blocked_Space* fspace = (Blocked_Space*)gc->nos;
-  Blocked_Space* mspace = (Blocked_Space*)gc->mos;
+  Space* nos = (Space*)gc->nos;
+  Space* mos = (Space*)gc->mos;
 
   float survive_ratio = 0.2f;
+  
+  if( MOS_RESERVE_SIZE != 0)
+    DEFAULT_MOS_RESERVE_SIZE = MOS_RESERVE_SIZE;
+
+  POINTER_SIZE_INT mos_free_size = mos_free_space_size(mos); 
+  /* for space free size computation, semispace may leave some nos space used. But we use a simple approximation here.
+      That is, we just use the totoal nos size as nos free size. This is important. We can't use real nos_free_space_size(), because
+      the whole algorithm here in gc_decide_next_collect() assumes total free size is reduced after every minor collection, and 
+      can only be increased after major collection. Otherwise the algorithm is invalid. If we use nos_free_space_size(), we may
+      get an increased total free size after a minor collection. */
+  POINTER_SIZE_INT nos_free_size = space_committed_size(nos);  
 
-  POINTER_SIZE_INT mos_free_size = blocked_space_free_mem_size(mspace);
-  POINTER_SIZE_INT nos_free_size = blocked_space_free_mem_size(fspace);
-  assert(nos_free_size == space_committed_size((Space*)fspace));
   POINTER_SIZE_INT total_free_size = mos_free_size  + nos_free_size;
   if(gc_match_kind((GC*)gc, MAJOR_COLLECTION)) gc->force_gen_mode = FALSE;
   if(!gc->force_gen_mode){
     /*Major collection:*/
     if(gc_match_kind((GC*)gc, MAJOR_COLLECTION)){
-      mspace->time_collections += pause_time;
+      mos->time_collections += pause_time;
   
       Tslow = (float)pause_time;
       SMax = total_free_size;
-      /*If fall back happens, and nos_boundary is up to heap_ceiling, then we force major.*/
-      if(((Fspace*)gc->nos)->num_managed_blocks == 0)
+      /*If fall back happens, and nos_boundary reaches heap_ceiling, then we force major.*/
+      if( nos_free_size == 0)
         gc->force_major_collect = TRUE;
       else gc->force_major_collect = FALSE;
       
       /*If major is caused by LOS, or collection kind is EXTEND_COLLECTION, all survive ratio is not updated.*/
       if((gc->cause != GC_CAUSE_LOS_IS_FULL) && (!gc_match_kind((GC*)gc, EXTEND_COLLECTION))){
-        survive_ratio = (float)mspace->period_surviving_size/(float)mspace->committed_heap_size;
-        mspace->survive_ratio = survive_ratio;
+        survive_ratio = (float)mos->period_surviving_size/(float)mos->committed_heap_size;
+        mos->survive_ratio = survive_ratio;
       }
-      /*If there is no minor collection at all, we must give mspace expected threshold a reasonable value.*/
-      if((gc->tuner->kind != TRANS_NOTHING) && (fspace->num_collections == 0))
-        mspace_set_expected_threshold_ratio((Mspace *)mspace, 0.5f);
-      /*If this major is caused by fall back compaction, we must give fspace->survive_ratio 
+      /*If there is no minor collection at all, we must give mos expected threshold a reasonable value.*/
+      if((gc->tuner->kind != TRANS_NOTHING) && (nos->num_collections == 0))
+        mspace_set_expected_threshold_ratio((Mspace *)mos, 0.5f);
+      /*If this major is caused by fall back compaction, we must give nos->survive_ratio 
         *a conservative and reasonable number to avoid next fall back.
-        *In fallback compaction, the survive_ratio of mspace must be 1.*/
-      if(gc_match_kind((GC*)gc, FALLBACK_COLLECTION)) fspace->survive_ratio = 1;
+        *In fallback compaction, the survive_ratio of mos must be 1.*/
+      if(gc_match_kind((GC*)gc, FALLBACK_COLLECTION)) nos->survive_ratio = 1;
 
     }
     /*Minor collection:*/    
     else
     {
       /*Give a hint to mini_free_ratio. */
-      if(fspace->num_collections == 1){
+      if(nos->num_collections == 1){
         /*Fixme: This is only set for tuning the first warehouse!*/
         Tslow = pause_time / gc->survive_ratio;
         SMax = (POINTER_SIZE_INT)((float)(gc->committed_heap_size - gc->los->committed_heap_size) * ( 1 - gc->survive_ratio ));
         last_total_free_size = gc->committed_heap_size - gc->los->committed_heap_size;
       }
   
-      fspace->time_collections += pause_time;  
+      nos->time_collections += pause_time;  
       POINTER_SIZE_INT free_size_threshold;
 
       POINTER_SIZE_INT minor_surviving_size = last_total_free_size - total_free_size;
-      /*If the first GC is caused by LOS, mspace->last_alloced_size should be smaller than this minor_surviving_size
+      /*If the first GC is caused by LOS, mos->last_alloced_size should be smaller than this minor_surviving_size
         *Because the last_total_free_size is not accurate.*/
-      if(fspace->num_collections != 1) assert(minor_surviving_size == mspace->last_alloced_size);
-  
-      float k = Tslow * fspace->num_collections/fspace->time_collections;
-      float m = ((float)minor_surviving_size)*1.0f/((float)(SMax - MOS_EXTRA_REMAIN_SIZE_TO_ANTI_FALLBACK ));
+      extern unsigned int MINOR_ALGO;
+      if(nos->num_collections != 1){
+      	assert(minor_surviving_size == mos->last_alloced_size);
+      }
+        
+      float k = Tslow * nos->num_collections/nos->time_collections;
+      float m = ((float)minor_surviving_size)*1.0f/((float)(SMax - DEFAULT_MOS_RESERVE_SIZE ));
       float free_ratio_threshold = mini_free_ratio(k, m);
 
-      if(SMax > MOS_EXTRA_REMAIN_SIZE_TO_ANTI_FALLBACK )
-        free_size_threshold = (POINTER_SIZE_INT)(free_ratio_threshold * (SMax - MOS_EXTRA_REMAIN_SIZE_TO_ANTI_FALLBACK  ) + MOS_EXTRA_REMAIN_SIZE_TO_ANTI_FALLBACK  );
+      if(SMax > DEFAULT_MOS_RESERVE_SIZE )
+        free_size_threshold = (POINTER_SIZE_INT)(free_ratio_threshold * (SMax - DEFAULT_MOS_RESERVE_SIZE  ) + DEFAULT_MOS_RESERVE_SIZE  );
       else
         free_size_threshold = (POINTER_SIZE_INT)(free_ratio_threshold * SMax);
 
-/*Fixme: if the total free size is lesser than threshold, the time point might be too late!
- *Have a try to test whether the backup solution is better for specjbb.
- */
-//   if ((mos_free_size + nos_free_size + minor_surviving_size) < free_size_threshold) gc->force_major_collect = TRUE;  
+      /* FIXME: if the total free size is lesser than threshold, the time point might be too late!
+       * Have a try to test whether the backup solution is better for specjbb.
+       */
+      //   if ((mos_free_size + nos_free_size + minor_surviving_size) < free_size_threshold) gc->force_major_collect = TRUE;  
       if ((mos_free_size + nos_free_size)< free_size_threshold) gc->force_major_collect = TRUE;
   
-      survive_ratio = (float)minor_surviving_size/(float)space_committed_size((Space*)fspace);
-      fspace->survive_ratio = survive_ratio;
+      survive_ratio = (float)minor_surviving_size/(float)space_committed_size((Space*)nos);
+      nos->survive_ratio = survive_ratio;
       /*For LOS_Adaptive*/
-      POINTER_SIZE_INT mspace_committed_size = space_committed_size((Space*)mspace);
-      POINTER_SIZE_INT fspace_committed_size = space_committed_size((Space*)fspace);
-      if(mspace_committed_size  + fspace_committed_size > free_size_threshold){
-        POINTER_SIZE_INT mspace_size_threshold;
-        mspace_size_threshold = mspace_committed_size  + fspace_committed_size - free_size_threshold;
-        float mspace_size_threshold_ratio = (float)mspace_size_threshold / (mspace_committed_size  + fspace_committed_size);
-        mspace_set_expected_threshold_ratio((Mspace *)mspace, mspace_size_threshold_ratio);
+      POINTER_SIZE_INT mos_committed_size = space_committed_size((Space*)mos);
+      POINTER_SIZE_INT nos_committed_size = space_committed_size((Space*)nos);
+      if(mos_committed_size  + nos_committed_size > free_size_threshold){
+        POINTER_SIZE_INT mos_size_threshold;
+        mos_size_threshold = mos_committed_size  + nos_committed_size - free_size_threshold;
+        float mos_size_threshold_ratio = (float)mos_size_threshold / (mos_committed_size  + nos_committed_size);
+        mspace_set_expected_threshold_ratio((Mspace *)mos, mos_size_threshold_ratio);
       }
     }
   
@@ -282,57 +292,66 @@
   return;
 }
 
-
+/* FIXME:: In this algorithm, it assumes NOS is a full forward space. 
+   Semispace GC's NOS has survivor_area. Need careful rethinking. 
+   But this algorithm so far can be a good approximation. */
 Boolean gc_compute_new_space_size(GC_Gen* gc, POINTER_SIZE_INT* mos_size, POINTER_SIZE_INT* nos_size)
 {
-  Blocked_Space* fspace = (Blocked_Space*)gc->nos;
-  Blocked_Space* mspace = (Blocked_Space*)gc->mos;
-  Blocked_Space* lspace = (Blocked_Space*)gc->los;  
+  Blocked_Space* nos = (Blocked_Space*)gc->nos;
+  Blocked_Space* mos = (Blocked_Space*)gc->mos;
+  Space* los = gc->los;  
   
   POINTER_SIZE_INT new_nos_size;
   POINTER_SIZE_INT new_mos_size;
 
-  POINTER_SIZE_INT curr_nos_size = space_committed_size((Space*)fspace);
-  POINTER_SIZE_INT used_mos_size = blocked_space_used_mem_size(mspace);
+  POINTER_SIZE_INT curr_nos_size = space_committed_size((Space*)nos);
+  // POINTER_SIZE_INT used_nos_size = nos_used_space_size((Space*)nos);
+  POINTER_SIZE_INT used_mos_size = mos_used_space_size((Space*)mos);
 
-  POINTER_SIZE_INT total_size;
+  POINTER_SIZE_INT total_size; /* total_size is no-LOS spaces size */
 
 #ifdef STATIC_NOS_MAPPING
-    total_size = max_heap_size_bytes - lspace->committed_heap_size;
+    total_size = max_heap_size_bytes - space_committed_size(los);
 #else
     POINTER_SIZE_INT curr_heap_commit_end = 
                               (POINTER_SIZE_INT)gc->heap_start + LOS_HEAD_RESERVE_FOR_HEAP_NULL + gc->committed_heap_size;
-    assert(curr_heap_commit_end > (POINTER_SIZE_INT)mspace->heap_start);
-    total_size = curr_heap_commit_end - (POINTER_SIZE_INT)mspace->heap_start;
+    assert(curr_heap_commit_end > (POINTER_SIZE_INT)mos->heap_start);
+    total_size = curr_heap_commit_end - (POINTER_SIZE_INT)mos->heap_start;
 #endif
   assert(total_size >= used_mos_size);
   POINTER_SIZE_INT total_free = total_size - used_mos_size;
   /*If total free is smaller than one block, there is no room for us to adjust*/
   if(total_free < GC_BLOCK_SIZE_BYTES)  return FALSE;
 
-  /*To reserve some MOS space to avoid fallback situation. 
-   *But we need ensure nos has at least one block.
-   *We have such fomula here:
-   *NOS_SIZE + NOS_SIZE * anti_fall_back_ratio + NOS_SIZE * survive_ratio = TOTAL_FREE*/
-  POINTER_SIZE_INT anti_fallback_size_in_mos;
-  float ratio_of_anti_fallback_size_to_nos = 0.25f;
   POINTER_SIZE_INT nos_reserve_size;
-  anti_fallback_size_in_mos = (POINTER_SIZE_INT)(((float)total_free * ratio_of_anti_fallback_size_to_nos)/(1.0f + ratio_of_anti_fallback_size_to_nos + fspace->survive_ratio));
-  if(anti_fallback_size_in_mos > MOS_EXTRA_REMAIN_SIZE_TO_ANTI_FALLBACK ){
-    /*If the computed anti_fallback_size_in_mos is too large, we reset it back to MOS_EXTRA_REMAIN_SIZE_TO_ANTI_FALLBACK .*/
-    anti_fallback_size_in_mos = MOS_EXTRA_REMAIN_SIZE_TO_ANTI_FALLBACK ;
-    /*Here, anti_fallback_size_in_mos must be smaller than TOTAL_FREE*/
-    nos_reserve_size = (POINTER_SIZE_INT)(((float)(total_free - anti_fallback_size_in_mos))/(1.0f + fspace->survive_ratio)); 
+  if( MOS_RESERVE_SIZE == 0){
+    /*To reserve some MOS space to avoid fallback situation. 
+     *But we need ensure nos has at least one block.
+     *We have such fomula here:
+     *NOS_SIZE + NOS_SIZE * anti_fall_back_ratio + NOS_SIZE * survive_ratio = TOTAL_FREE*/
+    POINTER_SIZE_INT anti_fallback_size_in_mos;
+    float ratio_of_anti_fallback_size_to_nos = 0.25f;
+    anti_fallback_size_in_mos = (POINTER_SIZE_INT)(((float)total_free * ratio_of_anti_fallback_size_to_nos)/(1.0f + ratio_of_anti_fallback_size_to_nos + nos->survive_ratio));
+    if(anti_fallback_size_in_mos > DEFAULT_MOS_RESERVE_SIZE ){
+      /*If the computed anti_fallback_size_in_mos is too large, we reset it back to DEFAULT_MOS_RESERVE_SIZE .*/
+      anti_fallback_size_in_mos = DEFAULT_MOS_RESERVE_SIZE ;
+      /*Here, anti_fallback_size_in_mos must be smaller than TOTAL_FREE*/
+      nos_reserve_size = (POINTER_SIZE_INT)(((float)(total_free - anti_fallback_size_in_mos))/(1.0f + nos->survive_ratio)); 
+    }else{
+      nos_reserve_size = (POINTER_SIZE_INT)(((float)total_free)/(1.0f + ratio_of_anti_fallback_size_to_nos + nos->survive_ratio));
+    }
+    
   }else{
-    nos_reserve_size = (POINTER_SIZE_INT)(((float)total_free)/(1.0f + ratio_of_anti_fallback_size_to_nos + fspace->survive_ratio));
+    nos_reserve_size = total_free - MOS_RESERVE_SIZE;
   }
+  
   /*NOS should not be zero, if there is only one block in non-los, i.e. in the former if sentence,
     *if total_free = GC_BLOCK_SIZE_BYTES, then the computed nos_reserve_size is between zero
     *and GC_BLOCK_SIZE_BYTES. In this case, we assign this block to NOS*/
   if(nos_reserve_size <= GC_BLOCK_SIZE_BYTES)  nos_reserve_size = GC_BLOCK_SIZE_BYTES;
 
 #ifdef STATIC_NOS_MAPPING
-  if(nos_reserve_size > fspace->reserved_heap_size) nos_reserve_size = fspace->reserved_heap_size;
+  if(nos_reserve_size > nos->reserved_heap_size) nos_reserve_size = nos->reserved_heap_size;
 #endif  
 
   new_nos_size = round_down_to_size((POINTER_SIZE_INT)nos_reserve_size, GC_BLOCK_SIZE_BYTES); 
@@ -340,12 +359,12 @@
   if(gc->force_gen_mode){
     new_nos_size = min_nos_size_bytes;
   }
-  
+ 
   new_mos_size = total_size - new_nos_size;
 #ifdef STATIC_NOS_MAPPING
-  if(new_mos_size > mspace->reserved_heap_size) new_mos_size = mspace->reserved_heap_size;
+  if(new_mos_size > mos->reserved_heap_size) new_mos_size = mos->reserved_heap_size;
 #endif
-  assert(new_nos_size + new_mos_size == total_size);
+
   *nos_size = new_nos_size;
   *mos_size = new_mos_size;
   return TRUE;;
@@ -358,8 +377,8 @@
 
   if(NOS_SIZE) return;
 
-  Blocked_Space* fspace = (Blocked_Space*)gc->nos;
-  Blocked_Space* mspace = (Blocked_Space*)gc->mos;
+  Blocked_Space* nos = (Blocked_Space*)gc->nos;
+  Blocked_Space* mos = (Blocked_Space*)gc->mos;
   
   POINTER_SIZE_INT new_nos_size;
   POINTER_SIZE_INT new_mos_size;
@@ -368,7 +387,7 @@
 
   if(!result) return;
 
-  POINTER_SIZE_INT curr_nos_size = space_committed_size((Space*)fspace);
+  POINTER_SIZE_INT curr_nos_size = space_committed_size((Space*)nos);
 
   //if( ABS_DIFF(new_nos_size, curr_nos_size) < NOS_COPY_RESERVE_DELTA )
   if( new_nos_size == curr_nos_size ){
@@ -390,30 +409,21 @@
   /* below are ajustment */  
   POINTER_SIZE_INT curr_heap_commit_end = 
                              (POINTER_SIZE_INT)gc->heap_start + LOS_HEAD_RESERVE_FOR_HEAP_NULL + gc->committed_heap_size;
-  nos_boundary = (void*)(curr_heap_commit_end - new_nos_size);
+  
+  void* new_nos_boundary = (void*)(curr_heap_commit_end - new_nos_size);
 
-  fspace->heap_start = nos_boundary;
-  fspace->blocks = (Block*)nos_boundary;
-  fspace->committed_heap_size = new_nos_size;
-  fspace->num_managed_blocks = (unsigned int)(new_nos_size >> GC_BLOCK_SHIFT_COUNT);
-  fspace->num_total_blocks = fspace->num_managed_blocks;
-  fspace->first_block_idx = ((Block_Header*)nos_boundary)->block_idx;
-  fspace->free_block_idx = fspace->first_block_idx;
-  if( NOS_PARTIAL_FORWARD )
-    object_forwarding_boundary = (void*)&fspace->blocks[fspace->num_managed_blocks >>1];
-  else
-    object_forwarding_boundary = (void*)&fspace->blocks[fspace->num_managed_blocks];
-
-  mspace->heap_end = nos_boundary;
-  mspace->committed_heap_size = new_mos_size;
-  mspace->num_managed_blocks = (unsigned int)(new_mos_size >> GC_BLOCK_SHIFT_COUNT);
-  mspace->num_total_blocks = mspace->num_managed_blocks;
-  mspace->ceiling_block_idx = ((Block_Header*)nos_boundary)->block_idx - 1;
-
-  Block_Header* mos_last_block = (Block_Header*)&mspace->blocks[mspace->num_managed_blocks-1];
-  assert(mspace->ceiling_block_idx == mos_last_block->block_idx);
-  Block_Header* nos_first_block = (Block_Header*)&fspace->blocks[0];
-  /* this is redundant: mos_last_block->next = nos_first_block; */
+  nos_boundary = nos_space_adjust((Space*)nos, new_nos_boundary, new_nos_size);
+  /* it's possible that nos can't accept the specified nos boundary, it gives a new one. */
+  assert(nos_boundary <= new_nos_boundary); 
+  
+  new_mos_size -= (POINTER_SIZE_INT)new_nos_boundary - (POINTER_SIZE_INT)nos_boundary;
+  blocked_space_adjust(mos, mos->heap_start, new_mos_size);
+  
+  Block_Header* mos_last_block = (Block_Header*)&mos->blocks[mos->num_managed_blocks-1];
+  assert(mos->ceiling_block_idx == mos_last_block->block_idx);
+  Block_Header* nos_first_block = (Block_Header*)&nos->blocks[0];
+  /* this is redundant, because blocked_space_adjust doesn't set last block next to NULL.
+  mos_last_block->next = nos_first_block; */
 
   if( gc_is_gen_mode())
     HelperClass_set_NosBoundary(nos_boundary);
@@ -421,8 +431,8 @@
   return;
 }
 
-/* ifdef STATIC_NOS_MAPPING */
-#else
+#else /* i.e., #ifdef STATIC_NOS_MAPPING */
+
 void gc_gen_adapt(GC_Gen* gc, int64 pause_time)
 {
   gc_decide_next_collect(gc, pause_time);
@@ -436,10 +446,10 @@
 
   if(!result) return;
 
-  Blocked_Space* fspace = (Blocked_Space*)gc->nos;
-  Blocked_Space* mspace = (Blocked_Space*)gc->mos;
+  Blocked_Space* nos = (Blocked_Space*)gc->nos;
+  Blocked_Space* mos = (Blocked_Space*)gc->mos;
   
-  POINTER_SIZE_INT curr_nos_size = space_committed_size((Space*)fspace);
+  POINTER_SIZE_INT curr_nos_size = space_committed_size((Space*)nos);
 
   //if( ABS_DIFF(new_nos_size, curr_nos_size) < NOS_COPY_RESERVE_DELTA )
   if( new_nos_size == curr_nos_size ){
@@ -458,13 +468,13 @@
       <<" size was transferred from nos to mos)\n"); 
   }
   
-  POINTER_SIZE_INT used_mos_size = blocked_space_used_mem_size((Blocked_Space*)mspace);
-  POINTER_SIZE_INT free_mos_size = blocked_space_free_mem_size((Blocked_Space*)mspace);
+  POINTER_SIZE_INT used_mos_size = blocked_space_used_mem_size((Blocked_Space*)mos);
+  POINTER_SIZE_INT free_mos_size = blocked_space_free_mem_size((Blocked_Space*)mos);
 
   POINTER_SIZE_INT new_free_mos_size = new_mos_size -  used_mos_size;
   
-  POINTER_SIZE_INT curr_mos_end = (POINTER_SIZE_INT)&mspace->blocks[mspace->free_block_idx - mspace->first_block_idx];
-  POINTER_SIZE_INT mos_border = (POINTER_SIZE_INT)mspace->heap_end;
+  POINTER_SIZE_INT curr_mos_end = (POINTER_SIZE_INT)&mos->blocks[mos->free_block_idx - mos->first_block_idx];
+  POINTER_SIZE_INT mos_border = (POINTER_SIZE_INT)mos->heap_end;
   if(  curr_mos_end + new_free_mos_size > mos_border){
     /* we can't let mos cross border */
     new_free_mos_size = mos_border - curr_mos_end;    
@@ -473,17 +483,17 @@
   if(new_nos_size < curr_nos_size){
   /* lets shrink nos */
     assert(new_free_mos_size > free_mos_size);
-    blocked_space_shrink((Blocked_Space*)fspace, curr_nos_size - new_nos_size);
-    blocked_space_extend((Blocked_Space*)mspace, new_free_mos_size - free_mos_size);
+    blocked_space_shrink((Blocked_Space*)nos, curr_nos_size - new_nos_size);
+    blocked_space_extend((Blocked_Space*)mos, new_free_mos_size - free_mos_size);
   }else if(new_nos_size > curr_nos_size){
     /* lets grow nos */
     assert(new_free_mos_size < free_mos_size);
-    blocked_space_shrink((Blocked_Space*)mspace, free_mos_size - new_free_mos_size);
-    blocked_space_extend((Blocked_Space*)fspace, new_nos_size - curr_nos_size);     
+    blocked_space_shrink((Blocked_Space*)mos, free_mos_size - new_free_mos_size);
+    blocked_space_extend((Blocked_Space*)nos, new_nos_size - curr_nos_size);     
   }
 
-  Block_Header* mos_last_block = (Block_Header*)&mspace->blocks[mspace->num_managed_blocks-1];
-  Block_Header* nos_first_block = (Block_Header*)&fspace->blocks[0];
+  Block_Header* mos_last_block = (Block_Header*)&mos->blocks[mos->num_managed_blocks-1];
+  Block_Header* nos_first_block = (Block_Header*)&nos->blocks[0];
   mos_last_block->next = nos_first_block;
   
   return;



Mime
View raw message