JDK-8164612 : NoSuchMethodException when method name contains NULL or Latin-1 supplement character
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 9
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2016-08-22
  • Updated: 2017-08-07
  • Resolved: 2016-10-26
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.
JDK 9
9 b146Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+132)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+132, mixed mode)

A DESCRIPTION OF THE PROBLEM :
When the name of a generated method contains the NULL character (U+0000) or a Latin-1 supplement character (U+0080 - U+00FF), a java.lang.NoSuchMethodException is thrown when trying to call that method. 

REGRESSION.  Last worked in version 8u102

ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute in jjs:

jjs> ({get "\0"(){}})["\0"]
jdk.nashorn.internal.lookup.MethodHandleFactory$LookupException: java.lang.NoSuchMethodException: no such method: jdk.nashorn.internal.scripts.Script$Recompilation$2$2$\^shell\_/585324508.get (Object)Object/invokeStatic

jjs> ({get "\x80"(){}})["\x80"]
jdk.nashorn.internal.lookup.MethodHandleFactory$LookupException: java.lang.NoSuchMethodException: no such method: jdk.nashorn.internal.scripts.Script$Recompilation$5$2$\^shell\_/1866875501.get ��(Object)Object/invokeStatic

jjs> ({get "\xff"(){}})["\xff"]
jdk.nashorn.internal.lookup.MethodHandleFactory$LookupException: java.lang.NoSuchMethodException: no such method: jdk.nashorn.internal.scripts.Script$Recompilation$8$2$\^shell\_/1910438136.get ��(Object)Object/invokeStatic

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No NoSuchMethodExceptions are thrown.
ACTUAL -
NoSuchMethodExceptions are thrown.

REPRODUCIBILITY :
This bug can be reproduced always.


Comments
Fix verified by regression test.
07-08-2017

The test executes Java Script code that defines getter methods containing Latin-1 supplement characters (0x80 - 0xFF). Those methods are registered at runtime through anonymous classes via Unsafe_DefineAnonymousClass. When calling a method, the VM fails with a NoSuchMethodException in MethodHandles::resolve_MemberName(). The failure happens while looking up the method name symbol in java_lang_String::as_symbol_or_null() [1]: 544 jbyte* position = (length == 0) ? NULL : value->byte_at_addr(0); 545 const char* base = UNICODE::as_utf8(position, length); 546 return SymbolTable::probe(base, length); If Compact Strings is enabled, we pass the Latin-1 encoded method name to UNICODE::as_utf8() and probe for the UTF-8 String in the SymbolTable. Since the Latin-1 method name contains non-ASCII characters, the length of the resulting UTF-8 String is larger (characters >= 0x80 are encoded as two bytes in UTF-8). However, we pass the shorter Latin-1 length to SymbolTable::probe() resulting in a lookup failure. I fixed this by passing the String length by reference to UNICODE::as_utf8(). I also refactored the related code in utf8.cpp, added comments and updated the callers: http://cr.openjdk.java.net/~thartmann/8164612/webrev.00/
18-10-2016

ILW = incorrect behavior (NoSuchMethodError is thrown), easy to reproduce, disable CompactStrings (-XX:-CompactStrings) = HHL = P2
17-10-2016

This appears to be a change in the method handle name lookup.
13-10-2016

b93 is when compact strings was integrated. Passing to compiler team.
13-10-2016

Good research Srini. Do you think you can create a simple Java based test case that we can pass off to the Hotspot team?
06-10-2016

To reproduce the issue, execute the following from the jjs shell: jjs> ({get "\0"(){}})["\0"] jjs> ({get "\x80"(){}})["\x80"] jjs> ({get "\xff"(){}})["\xff"] Following are the results on various JDK versions: JDK 8u102 - Pass JDK 8u112ea - Pass JDK 9ea b92 - Pass JDK 9ea b93 - Fail JDK 9ea b132 - Fail Output on the failed cases: jjs> ({get "\0"(){}})["\0"] jdk.nashorn.internal.lookup.MethodHandleFactory$LookupException: java.lang.NoSuchMethodException: no such method: jdk.nashorn.internal.scripts.Script$Recompilation$2$2$\^shell\_/1580297332.get (Object)Object/invokeStatic
23-08-2016