You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by va...@apache.org on 2007/01/26 09:14:08 UTC

svn commit: r500175 - in /harmony/enhanced/drlvm/trunk/vm: tests/smoke/thread/ThreadOOM.java thread/src/thread_java_basic.c

Author: varlax
Date: Fri Jan 26 00:14:07 2007
New Revision: 500175

URL: http://svn.apache.org/viewvc?view=rev&rev=500175
Log:
HARMONY-2437 [drlvm] out of memory creating unused Threads
Tested on Win32, SUSE9@ia32 SUSE9@x64

Added:
    harmony/enhanced/drlvm/trunk/vm/tests/smoke/thread/ThreadOOM.java
Modified:
    harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c

Added: harmony/enhanced/drlvm/trunk/vm/tests/smoke/thread/ThreadOOM.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/smoke/thread/ThreadOOM.java?view=auto&rev=500175
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/smoke/thread/ThreadOOM.java (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/smoke/thread/ThreadOOM.java Fri Jan 26 00:14:07 2007
@@ -0,0 +1,41 @@
+/*
+ *  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.
+ */
+
+package thread;
+
+public class ThreadOOM extends Thread {
+    public static void main(String[] args) {
+        try {
+            for (int i = 0; i < 100; i++) {
+                if (i % 10 == 0) {
+                    System.out.print(".");
+                    System.out.flush();
+                }
+                new ThreadOOM();
+            }
+            System.out.println("\nPASSED");
+        } catch (Throwable e) {
+            System.out.println("\nFAILED: " + e);
+        }
+    }
+
+    byte[] padding;
+
+    public ThreadOOM() {
+        padding = new byte[16*1048576];
+    }
+}

Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c?view=diff&rev=500175&r1=500174&r2=500175
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c Fri Jan 26 00:14:07 2007
@@ -147,6 +147,7 @@
 
     tm_java_thread = hythread_get_private_data(tm_native_thread);
     assert(tm_java_thread);
+    tm_java_thread->thread_object = (*jni_env)->NewGlobalRef(jni_env, java_thread);
 
     data = apr_palloc(tm_java_thread->pool, sizeof(wrapper_proc_data));
     if (data == NULL) {
@@ -202,6 +203,7 @@
 
     jvmti_thread = hythread_get_private_data(tm_native_thread);
     assert(jvmti_thread);
+    jvmti_thread->thread_object = (*jni_env)->NewGlobalRef(jni_env, java_thread);
     jvmti_thread->jenv = jni_env;
     jvmti_thread->daemon = daemon;
 
@@ -320,7 +322,6 @@
     }
     // JNI environment is created when this thread attaches to VM.
     tm_java_thread->jenv = NULL;
-    tm_java_thread->thread_object = (*jni_env)->NewGlobalRef(jni_env, java_thread);
     tm_java_thread->thread_ref    = (thread_ref) ? (*jni_env)->NewGlobalRef(jni_env, thread_ref) : NULL; 
     tm_java_thread->contended_monitor = 0;
     tm_java_thread->wait_monitor = 0;