harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r567561 - in /harmony/enhanced/classlib/trunk/modules/luni/src/main: java/org/apache/harmony/luni/platform/ native/luni/shared/ native/luni/unix/ native/luni/windows/
Date Mon, 20 Aug 2007 07:00:24 GMT
Author: leoli
Date: Mon Aug 20 00:00:23 2007
New Revision: 567561

URL: http://svn.apache.org/viewvc?rev=567561&view=rev
Log:
Apply patch for HARMONY-3148( [Classlib][nio] alloc many DirectByteBuffers may cause memory-out-error).

Added:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSResourcesMonitor.java
  (with props)
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSResourcesMonitor.h
  (with props)
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSResourcesMonitorLinux.c
  (with props)
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSResourcesMonitorWin32.c
Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSMemory.c
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSMemory.h
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/exports.txt
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/makefile
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemory.c
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemory.h
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/makefile

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java?rev=567561&r1=567560&r2=567561&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
Mon Aug 20 00:00:23 2007
@@ -122,7 +122,12 @@
 	 * @throws OutOfMemoryError
 	 *             if the request cannot be satisfied.
 	 */
-	public native long malloc(long length) throws OutOfMemoryError;
+	public long malloc(long length) throws OutOfMemoryError
+    {
+        OSResourcesMonitor.ensurePhysicalMemoryCapacity();
+        return mallocNative(length);  
+    }
+    private native long mallocNative(long length) throws OutOfMemoryError;
 
 	/**
 	 * Deallocates space for a memory block that was previously allocated by a

Added: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSResourcesMonitor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSResourcesMonitor.java?rev=567561&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSResourcesMonitor.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSResourcesMonitor.java
Mon Aug 20 00:00:23 2007
@@ -0,0 +1,53 @@
+/*
+ *  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 org.apache.harmony.luni.platform;
+
+public class OSResourcesMonitor {
+    private static final int MAX_ITERATION_TIMES = 2;
+
+    private static final int SLEEP_TIME = 50;
+
+    private static final long FREE_MEMORY_THRESHOLD = 64 * 1024 * 1024; // 64M.
+
+    private static final int MEMORY_LOAD_THRESHOLD = 80; // 80%
+                                                                            // left.
+
+    public static void ensurePhysicalMemoryCapacity() {
+        if (!isSystemPhysicalMemoryLow()) {           
+            return;
+        }
+        synchronized (OSResourcesMonitor.class) {
+            int iteration = 0;
+            while (isSystemPhysicalMemoryLow()) {               
+                if (iteration > MAX_ITERATION_TIMES) {                    
+                    return;
+                }                
+                iteration++;
+                System.gc();                
+                try {
+                    Thread.sleep(SLEEP_TIME);
+                } catch (InterruptedException e) {
+
+                }
+            }
+
+        }
+    }
+
+    private native static boolean isSystemPhysicalMemoryLow();   
+}

Propchange: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSResourcesMonitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSResourcesMonitor.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSResourcesMonitor.h?rev=567561&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSResourcesMonitor.h
(added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSResourcesMonitor.h
Mon Aug 20 00:00:23 2007
@@ -0,0 +1,39 @@
+/*
+ *  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.
+ */
+
+#include <jni.h>
+
+/* Header for class org_apache_harmony_luni_platform_OSResourcesMonitor */
+
+#ifndef _Included_org_apache_harmony_luni_platform_OSResourcesMonitor
+#define _Included_org_apache_harmony_luni_platform_OSResourcesMonitor
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Class:     org_apache_harmony_luni_platform_OSResourcesMonitor
+ * Method:    isSystemPhysicalMemoryLow
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_luni_platform_OSResourcesMonitor_isSystemPhysicalMemoryLow
+  (JNIEnv *, jclass);
+  
+#ifdef __cplusplus
+}
+#endif
+#endif

Propchange: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSResourcesMonitor.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSMemory.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSMemory.c?rev=567561&r1=567560&r2=567561&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSMemory.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSMemory.c Mon
Aug 20 00:00:23 2007
@@ -29,7 +29,7 @@
 #include "IMemorySystem.h"
 #include "exceptions.h"
 
-JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSMemory_malloc
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSMemory_mallocNative
   (JNIEnv * env, jobject thiz, jlong size)
 {
   PORT_ACCESS_FROM_ENV (env);

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSMemory.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSMemory.h?rev=567561&r1=567560&r2=567561&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSMemory.h (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSMemory.h Mon
Aug 20 00:00:23 2007
@@ -43,10 +43,10 @@
     (JNIEnv *, jclass);
 /*
  * Class:     org_apache_harmony_luni_platform_OSMemory
- * Method:    malloc
+ * Method:    mallocNative
  * Signature: (J)J
  */
-  JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSMemory_malloc
+  JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSMemory_mallocNative
     (JNIEnv *, jobject, jlong);
 /*
  * Class:     org_apache_harmony_luni_platform_OSMemory

Added: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSResourcesMonitorLinux.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSResourcesMonitorLinux.c?rev=567561&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSResourcesMonitorLinux.c
(added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSResourcesMonitorLinux.c
Mon Aug 20 00:00:23 2007
@@ -0,0 +1,49 @@
+/*
+ *  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.
+ */
+
+/*
+ * Utilities to monitor system resources.
+ */
+#include <sys/sysinfo.h>
+#include <hyport.h>
+#include "OSResourcesMonitor.h"
+
+static unsigned long MEMORYFREETHRESHOLD = 2 * 1024 * 1024; //2M
+static unsigned int MEMORYLOADTHRESHOLD = 98; // 98% load
+
+/*
+ * Class:     org_apache_harmony_luni_platform_OSResourcesMonitor
+ * Method:    isSystemPhysicalMemoryLow
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_luni_platform_OSResourcesMonitor_isSystemPhysicalMemoryLow
+  (JNIEnv *env, jclass thizClass)
+{
+	struct sysinfo info;
+	int memoryLoad = 100;		
+	if(0 == sysinfo(&info))
+	{
+	   
+	    memoryLoad = 100 - ((float)info.freeram/info.totalram) * 100;
+	    if(memoryLoad >= MEMORYLOADTHRESHOLD || info.freeram <= MEMORYFREETHRESHOLD)
+	    {
+	        return TRUE;
+	    }
+	}
+    return FALSE;	
+}
+ 

Propchange: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSResourcesMonitorLinux.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/exports.txt
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/exports.txt?rev=567561&r1=567560&r2=567561&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/exports.txt (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/exports.txt Mon
Aug 20 00:00:23 2007
@@ -179,7 +179,7 @@
 Java_org_apache_harmony_luni_platform_OSMemory_getPointerSizeImpl
 Java_org_apache_harmony_luni_platform_OSMemory_getAddress
 Java_org_apache_harmony_luni_platform_OSMemory_setAddress
-Java_org_apache_harmony_luni_platform_OSMemory_malloc
+Java_org_apache_harmony_luni_platform_OSMemory_mallocNative
 Java_org_apache_harmony_luni_platform_OSMemory_free
 Java_org_apache_harmony_luni_platform_OSMemory_memmove
 Java_org_apache_harmony_luni_platform_OSMemory_memset
@@ -247,5 +247,6 @@
 Java_org_apache_harmony_luni_platform_OSNetworkSystem_isReachableByICMPImpl
 Java_org_apache_harmony_luni_platform_OSNetworkSystem_inheritedChannelImpl
 Java_org_apache_harmony_luni_platform_OSNetworkSystem_oneTimeInitializationImpl
+Java_org_apache_harmony_luni_platform_OSResourcesMonitor_isSystemPhysicalMemoryLow
 Java_org_apache_harmony_luni_platform_Environment_getEnvBytes
 Java_org_apache_harmony_luni_platform_Environment_getEnvByName

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/makefile
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/makefile?rev=567561&r1=567560&r2=567561&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/makefile (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/makefile Mon Aug
20 00:00:23 2007
@@ -34,7 +34,7 @@
 	$(SHAREDSUB)filedesc.o $(SHAREDSUB)timezone.o \
 	$(SHAREDSUB)OSFileSystem.o OSFileSystemLinux32.o \
 	OSMemory.o OSMemoryLinux32.o $(SHAREDSUB)OSNetworkSystem.o \
-	OSNetworkSystemLinux.o hyenv.o
+	OSNetworkSystemLinux.o OSResourcesMonitorLinux.o hyenv.o 
 
 ifneq ($(HY_ZIP_API),true)
 MDLLIBFILES += $(LIBPATH)libhyzip.a $(DLLPATH)libhyzlib$(HY_LINKLIB_SUFFIX)

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemory.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemory.c?rev=567561&r1=567560&r2=567561&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemory.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemory.c Mon
Aug 20 00:00:23 2007
@@ -24,7 +24,7 @@
 #include "IMemorySystem.h"
 #include "exceptions.h"
 
-JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSMemory_malloc
+JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSMemory_mallocNative
   (JNIEnv * env, jobject thiz, jlong size)
 {
   PORT_ACCESS_FROM_ENV (env);

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemory.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemory.h?rev=567561&r1=567560&r2=567561&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemory.h (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemory.h Mon
Aug 20 00:00:23 2007
@@ -41,10 +41,10 @@
     (JNIEnv *, jclass);
 /*
  * Class:     org_apache_harmony_luni_platform_OSMemory
- * Method:    malloc
+ * Method:    mallocNative
  * Signature: (J)J
  */
-  JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSMemory_malloc
+  JNIEXPORT jlong JNICALL Java_org_apache_harmony_luni_platform_OSMemory_mallocNative
     (JNIEnv *, jobject, jlong);
 /*
  * Class:     org_apache_harmony_luni_platform_OSMemory

Added: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSResourcesMonitorWin32.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSResourcesMonitorWin32.c?rev=567561&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSResourcesMonitorWin32.c
(added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSResourcesMonitorWin32.c
Mon Aug 20 00:00:23 2007
@@ -0,0 +1,46 @@
+/* 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.
+ */
+
+/*
+ * Utilities to monitor system resources.
+ */ 
+
+#include <windows.h>
+#include "OSResourcesMonitor.h"
+
+unsigned long MEMORYFREETHRESHOLD = 32 * 1024 * 1024; //32M
+unsigned int MEMORYLOADTHRESHOLD = 90; //90% load
+
+/*
+ * Class:     org_apache_harmony_luni_platform_OSResourcesMonitor
+ * Method:    isSystemPhysicalMemoryLow
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_harmony_luni_platform_OSResourcesMonitor_isSystemPhysicalMemoryLow
+  (JNIEnv *env, jclass thizClass)
+{
+	MEMORYSTATUSEX statex;
+	statex.dwLength = sizeof (statex);
+	
+    if(GlobalMemoryStatusEx(&statex))
+    {     
+        if(statex.dwMemoryLoad >= MEMORYLOADTHRESHOLD || statex.ullAvailPhys <= MEMORYFREETHRESHOLD){
+    	    return TRUE;
+        }        
+    }    
+    return FALSE;	
+}
+  
\ No newline at end of file

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/makefile
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/makefile?rev=567561&r1=567560&r2=567561&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/makefile (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/makefile Mon
Aug 20 00:00:23 2007
@@ -37,7 +37,8 @@
   $(SHAREDSUB)filedesc.obj $(SHAREDSUB)timezone.obj \
   OSFileSystemWin32.obj hyenv.obj\
   $(SHAREDSUB)OSFileSystem.obj OSMemoryWin32.obj OSMemory.obj \
-  $(SHAREDSUB)OSNetworkSystem.obj OSNetworkSystemWin32.obj
+  $(SHAREDSUB)OSNetworkSystem.obj OSNetworkSystemWin32.obj \
+  OSResourcesMonitorWin32.obj
 
 VIRTFILES = hyluni.res
 



Mime
View raw message