JDK-4804447 : JNI GetArrayElements fails with zero length arrays.
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 1.4.2
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_8
  • CPU: sparc
  • Submitted: 2003-01-16
  • Updated: 2012-10-08
  • Resolved: 2003-02-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other Other
1.3.1_09 09Fixed 1.4.1_07Fixed 1.4.2Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
Sunone Appserver 7 fails to start with latest hotspot debug/fastdebug binaries

I tried the latest two putbacks from archive pages:
----
java version "1.4.2-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b12)
Java HotSpot(TM) Server VM (build 20030115110541.steved.main_baseline-product, mixed mode)
----
Both crash at the same location:typeArrayOop.hpp:44

Log:
[16/Jan/2003:12:05:23] INFO ( 6086): WEB0100: Loading web module [adminapp:adminapp.war] in virtual server [admin-server] at [/web1]
[16/Jan/2003:12:05:25] INFO ( 6086): WEB0100: Loading web module [admingui:adminGUI.war] in virtual server [admin-server] at [/admin]
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: # To suppress the following error report, specify this argument
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: # after -XX: or in .hotspotrc:  SuppressErrorAt=/typeArrayOop.hpp:44
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: #
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: # HotSpot Virtual Machine Error, assertion failure
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: # Please report this error at
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: # http://java.sun.com/cgi-bin/bugreport.cgi
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: #
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: # Java VM: Java HotSpot(TM) Server VM (20030114131733.jmasa.main_baseline_4802112-fastdebug-debug
 mixed mode)
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: #
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: # assert(is_within_bounds(which), "index out of bounds")
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: #
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: # Error ID: /export/imgr_home/ws/20030114131733.jmasa.main_baseline_4802112/src/share/vm/oops/typ
eArrayOop.hpp, 44 [ Patched ]
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: #
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: # Problematic Thread: prio=5 tid=0x0020bbe8 nid=0x1 runnable
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: #
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: Heap at VM Abort:
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: Heap
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr:  def new generation   total 2112K, used 500K [0xeb800000, 0xeba20000, 0xee2a0000)
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr:   eden space 2048K,  21% used [0xeb800000, 0xeb86d0d8, 0xeba00000)
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr:   from space 64K, 100% used [0xeba00000, 0xeba10000, 0xeba10000)
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr:   to   space 64K,   0% used [0xeba10000, 0xeba10000, 0xeba20000)
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr:  tenured generation   total 4104K, used 3771K [0xee2a0000, 0xee6a2000, 0xf3800000)
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr:    the space 4104K,  91% used [0xee2a0000, 0xee64efc8, 0xee64f000, 0xee6a2000)
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr:  compacting perm gen  total 16384K, used 11999K [0xf3800000, 0xf4800000, 0xf7800000)
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr:    the space 16384K,  73% used [0xf3800000, 0xf43b7ed8, 0xf43b8000, 0xf4800000)
[16/Jan/2003:12:05:32] WARNING ( 6086): CORE3283: stderr: Dumping core....

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.3.1_09 1.4.1_07 generic mantis-beta FIXED IN: 1.3.1_09 1.4.1_07 mantis-beta INTEGRATED IN: 1.3.1_09 1.4.1_07 mantis-b17 mantis-beta tiger-beta
14-06-2004

SUGGESTED FIX ###@###.### 2003-02-07 *** /export/hotspot/webrev/src/share/vm/prims/jni.cpp- Fri Feb 7 18:06:06 2003 --- /export/hotspot/webrev/src/share/vm/prims/jni.cpp+ Fri Feb 7 18:06:07 2003 *** 1500,1518 **** DEFINE_NEWSCALARARRAY(jlongArray, new_longArray, Long) DEFINE_NEWSCALARARRAY(jfloatArray, new_singleArray, Float) DEFINE_NEWSCALARARRAY(jdoubleArray, new_doubleArray, Double) #define DEFINE_GETSCALARARRAYELEMENTS(ElementTag,ElementType,Result, Tag) JNI_QUICK_ENTRY(ElementType*, jni_Get##Result##ArrayElements(JNIEnv *env, ElementType##Array array, jboolean *isCopy)) JNIWrapper("Get" XSTR(Result) "ArrayElements"); /* allocate an chunk of memory in c land */ typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); ! ElementType* result = NEW_C_HEAP_ARRAY(ElementType, a->length()); /* copy the array to the c chunk */ ! memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*a->length()); if (isCopy) *isCopy = JNI_TRUE; return result; JNI_END DEFINE_GETSCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool) --- 1500,1531 ---- DEFINE_NEWSCALARARRAY(jlongArray, new_longArray, Long) DEFINE_NEWSCALARARRAY(jfloatArray, new_singleArray, Float) DEFINE_NEWSCALARARRAY(jdoubleArray, new_doubleArray, Double) + // Array declared "const" so that it appears in the read-only data + // section of a library if possible, so caller can't modify it so easily. + static const double not_quite_null[] = {0, 0, 0, 0}; + #define DEFINE_GETSCALARARRAYELEMENTS(ElementTag,ElementType,Result, Tag) JNI_QUICK_ENTRY(ElementType*, jni_Get##Result##ArrayElements(JNIEnv *env, ElementType##Array array, jboolean *isCopy)) JNIWrapper("Get" XSTR(Result) "ArrayElements"); /* allocate an chunk of memory in c land */ typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); ! ElementType* result; ! int len = a->length(); ! if (len == 0) { ! /* Empty array: legal but useless, can't return NULL. ! * Return a pointer to something a caller is less likely to hurt ! * himself with. Avoid asserts in typeArrayOop. */ ! result = (ElementType*)not_quite_null; ! } else { ! result = NEW_C_HEAP_ARRAY(ElementType, len); /* copy the array to the c chunk */ ! memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); ! } if (isCopy) *isCopy = JNI_TRUE; return result; JNI_END DEFINE_GETSCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool) *** 1529,1544 **** JNI_QUICK_ENTRY(void, jni_Release##Result##ArrayElements(JNIEnv *env, ElementType##Array array, ElementType *buf, jint mode)) JNIWrapper("Release" XSTR(Result) "ArrayElements"); typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); if ((mode == 0) || (mode == JNI_COMMIT)) { ! memcpy(a->Tag##_at_addr(0), buf, sizeof(ElementType)*a->length()); } if ((mode == 0) || (mode == JNI_ABORT)) { FreeHeap(buf); } JNI_END DEFINE_RELEASESCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool) DEFINE_RELEASESCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte) DEFINE_RELEASESCALARARRAYELEMENTS(T_SHORT, jshort, Short, short) --- 1542,1560 ---- JNI_QUICK_ENTRY(void, jni_Release##Result##ArrayElements(JNIEnv *env, ElementType##Array array, ElementType *buf, jint mode)) JNIWrapper("Release" XSTR(Result) "ArrayElements"); typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); + int len = a->length(); + if (len != 0) { /* Empty array: nothing to free or copy. */ if ((mode == 0) || (mode == JNI_COMMIT)) { ! memcpy(a->Tag##_at_addr(0), buf, sizeof(ElementType)*len); } if ((mode == 0) || (mode == JNI_ABORT)) { FreeHeap(buf); } + } JNI_END DEFINE_RELEASESCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool) DEFINE_RELEASESCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte) DEFINE_RELEASESCALARARRAYELEMENTS(T_SHORT, jshort, Short, short)
11-06-2004

EVALUATION ###@###.### 2003-01-22 I am changing the subcategory to runtime_system since Madhava confirms that this assertion also fails with -client. I've asked Madhava to generate core files when he encounters this assertion failure so that we can investigate the stack trace. In addition, I've asked him to run the appserver using -XX:SupressErrorAt=/typeArrayOop.hpp:44 to look for later assertion failures. ----- ----- ###@###.### 2003-02-06 Commiting this for tiger. Since fastdebug binaries are not shipped, this does not meet mantis beta/fcs criteria. The problem (from the comments) is that the JNI Get<Type>ArrayElements methods fail (in non-product debug builds) when the array length is zero. ----- ----- ###@###.### 2003-02-06 There is a plan to ship fastdebug binaries in mantis. Since this assertion failure occurs early in execution of a major product it should be fixed. In addition, the fix would be a low-risk. ----- ----- ----------------------------------------------------------------- ###@###.### 2003-02-07 Attached simple test case. Fixed. -----------------------------------------------------------------
07-02-2003