harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From x..@apache.org
Subject svn commit: r528407 - in /harmony/enhanced/drlvm/trunk/vm: gc_cc/src/ tests/smoke/gc/ vmcore/src/init/ vmcore/src/kernel_classes/javasrc/java/lang/
Date Fri, 13 Apr 2007 09:37:06 GMT
Author: xli
Date: Fri Apr 13 02:37:02 2007
New Revision: 528407

URL: http://svn.apache.org/viewvc?view=rev&rev=528407
Log:
HARMONY-3590 : Fix broken finalization work balance subsystem.

Added:
    harmony/enhanced/drlvm/trunk/vm/tests/smoke/gc/SynchronizedFinalizersTest.java   (with
props)
Removed:
    harmony/enhanced/drlvm/trunk/vm/tests/smoke/gc/SynchronizedFinilazersTest.java
Modified:
    harmony/enhanced/drlvm/trunk/vm/gc_cc/src/gc_for_vm.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/finalize.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/FinalizerThread.java

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=528407&r1=528406&r2=528407
==============================================================================
--- 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 Fri Apr 13 02:37:02 2007
@@ -37,6 +37,8 @@
 
 fast_list<Partial_Reveal_Object*, 1024> finalizible_objects;
 
+static unsigned int pending_finalizers_hint_counter = 0;
+
 #ifdef POINTER64
 GCExport Boolean gc_supports_compressed_references() {
     vtable_base = (Ptr) vm_get_vtable_base();
@@ -233,9 +235,16 @@
     unsigned size = get_instance_data_size(in_size);
 
     if (gcvt->is_finalizible()) {
+        pending_finalizers_hint_counter++;
         unsigned char *obj;
         unsigned char *endpos;
         bool allocated = place_into_old_objects(obj, endpos, size);
+
+        if (pending_finalizers_hint_counter > 100) {
+            pending_finalizers_hint_counter = 0;
+            pending_finalizers = true;
+        }
+
         if (allocated) {
             memset(obj, 0, size);
             finalizible_objects.push_back((Partial_Reveal_Object*) obj);

Added: harmony/enhanced/drlvm/trunk/vm/tests/smoke/gc/SynchronizedFinalizersTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/smoke/gc/SynchronizedFinalizersTest.java?view=auto&rev=528407
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/smoke/gc/SynchronizedFinalizersTest.java (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/smoke/gc/SynchronizedFinalizersTest.java Fri Apr
13 02:37:02 2007
@@ -0,0 +1,130 @@
+/*
+ *  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 Pavel Afremov
+ * @version $Revision: 1.8.8.3.4.3 $
+ */
+
+package gc;
+
+/**
+ * Tests synchronized finalizers in multiple threads.
+ */
+public class SynchronizedFinalizersTest implements Runnable {
+    int n;
+    byte[] array;
+
+    static final int N_THREADS = 100;
+    static final int N_OBJECTS = 300;
+    static final int OBJECT_SIZE = 20000;
+
+    static int started = 0;
+    static int finished = 0;
+    static int created = 0;
+    static int finalized = 0;
+
+    static boolean stop = false;
+
+    public SynchronizedFinalizersTest(int nn) {
+        n=nn;
+        synchronized(SynchronizedFinalizersTest.class) {
+            created++;
+            array = new byte[OBJECT_SIZE];
+            checkPass();
+        }
+    }
+
+    public static void main(String[] args) {
+	updateInfo();  	
+
+        for (int i=0;i<N_THREADS ;i++) {
+            new Thread(new SynchronizedFinalizersTest(i)).start();
+        }
+    }
+ 
+    public void run() {
+        try {
+            synchronized(SynchronizedFinalizersTest.class) {
+                started++;
+                updateInfo();
+            }
+
+            for (int i=0;i<N_OBJECTS;i++) {
+                synchronized(SynchronizedFinalizersTest.class) {
+					new SynchronizedFinalizersTest(n*N_OBJECTS+i);
+				}
+
+                if (stop) {
+                    break;
+                }
+            }
+        } catch (Throwable e) {
+	    if (!stop) {
+	        stop = true;
+                System.err.println("Err:"+e+" in "+n);                                
+                System.err.println("FAILED");                                
+                System.err.flush();
+                System.out.println("Err:"+e+" in "+n);                                
+                System.out.println("FAILED");                                
+                System.out.flush();
+            }
+        } finally {
+            synchronized(SynchronizedFinalizersTest.class) {
+                finished++;
+                updateInfo();
+                checkPass();
+            }
+        }
+    }
+ 
+    protected void finalize() {            
+        synchronized(SynchronizedFinalizersTest.class) {
+            finalized ++;
+            updateInfo();
+            checkPass();
+        }
+    }
+
+    private static void checkPass() {
+	if ((!stop) &&
+                (started == N_THREADS) &&
+                (finished == N_THREADS) &&
+                (created == (N_THREADS * (N_OBJECTS+1)))) {
+	    stop = true;
+            System.err.println("\nPASSED");
+            System.err.flush();
+            System.out.println("\nPASSED");
+            System.out.flush();
+	}
+    }
+    private static void updateInfo() {
+	if (!stop) {
+            int startedPercent = 100 * started / (N_THREADS);
+            int finishedPercent = 100 * finished / (N_THREADS);
+            int createdPercent = 100 * created / (N_THREADS * (N_OBJECTS+1));
+            int finalizedPercent = 100 * finalized / (N_THREADS * (N_OBJECTS+1));
+
+            System.err.print("\r(" + startedPercent);
+            System.err.print("%, " + finishedPercent);
+            System.err.print("%, " + createdPercent);
+            System.err.print("%, " + finalizedPercent);
+            System.err.print("%)");
+            System.err.flush();
+        }    
+    }
+}
+

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/smoke/gc/SynchronizedFinalizersTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/finalize.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/finalize.cpp?view=diff&rev=528407&r1=528406&r2=528407
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/finalize.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/finalize.cpp Fri Apr 13 02:37:02 2007
@@ -384,12 +384,12 @@
     int num_objects = getLength() + vm_get_references_quantity();
 
     if (num_objects == 0) {
-        //return;
+        return;
     }
 
     if ((p_TLS_vmthread->finalize_thread_flags & (FINALIZER_STARTER | FINALIZER_THREAD))
!= 0) {
         TRACE2("finalize", "recursive finalization prevented");
-        //return;
+        return;
     }
 
     p_TLS_vmthread->finalize_thread_flags |= FINALIZER_STARTER;
@@ -401,7 +401,7 @@
     exn_clear();
     
     if (FRAME_COMPILATION ==
-            (FRAME_COMPILATION | m2n_get_frame_type(m2n_get_last_frame()))) {
+            (FRAME_COMPILATION & m2n_get_frame_type(m2n_get_last_frame()))) {
         assert(work_lock);
 
         IDATA r = jthread_monitor_try_enter(work_lock);
@@ -615,10 +615,12 @@
     NativeObjectHandles nhs;
     assert(hythread_is_suspend_enabled());
     /* BEGIN: modified for NATIVE FINALIZER THREAD */
-    if(get_native_finalizer_thread_flag())
+    if(get_native_finalizer_thread_flag()) {
         activate_finalizer_threads(FALSE);
-    else
+    }
+    else {
         objects_to_finalize.run_finalizers();
+    }
     /* END: modified for NATIVE FINALIZER THREAD */
 } //vm_run_pending_finalizers
 
@@ -626,7 +628,7 @@
 {
     assert(hythread_is_suspend_enabled());
     return objects_to_finalize.do_finalization(quantity);
-} //vm_run_pending_finalizers
+} //vm_do_finalization
 
 bool is_it_finalize_thread() {
     return ((p_TLS_vmthread->finalize_thread_flags & FINALIZER_THREAD) != 0);

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/FinalizerThread.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/FinalizerThread.java?view=diff&rev=528407&r1=528406&r2=528407
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/FinalizerThread.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/FinalizerThread.java
Fri Apr 13 02:37:02 2007
@@ -76,7 +76,6 @@
             trace("FinalizerThread: static initialization started");
         }
 
-        String p = System.getProperty("vm.finalize");
         processorsQuantity = getProcessorsQuantity();
 
         // -XDvm.finalize=0 disables the finalizer thread
@@ -254,7 +253,7 @@
 
         FinalizerThread newThread = null;
         if (waitFinishCounter >= MAX_THREADS) {
-            // do nothing
+			Thread.yield();
         } else {
             try {
                 for (int i = 0; i < processorsQuantity; i++) {



Mime
View raw message