JDK-8272290 : [lworld] Disable CDS if InlineTypePassFieldsAsArgs has changed
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: repo-valhalla
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-08-10
  • Updated: 2021-08-16
  • Resolved: 2021-08-16
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
repo-valhallaFixed
Related Reports
Relates :  
Description
When the attached patch to convert a few JDK classes to ref-default primitive classes, the following compiler tests fail with this assertion when the CDS sharing is on:
   assert(pos == TypeFunc::Parms + arg_cnt) failed: wrong number of arguments

compiler/valhalla/inlinetypes/TestArrays.java 
compiler/valhalla/inlinetypes/TestBasicFunctionality.java 
compiler/valhalla/inlinetypes/TestCallingConvention.java 
compiler/valhalla/inlinetypes/TestIntrinsics.java 
compiler/valhalla/inlinetypes/TestJNICalls.java 
compiler/valhalla/inlinetypes/TestLWorld.java 
compiler/valhalla/inlinetypes/TestMethodHandles.java 
compiler/valhalla/inlinetypes/TestNullableArrays.java 
compiler/valhalla/inlinetypes/TestNullableInlineTypes.java 
compiler/valhalla/inlinetypes/TestOnStackReplacement.java 

#  Internal Error (/Users/mlchung/ws/valhalla/lworld-closed/open/src/hotspot/share/opto/type.cpp:2163), pid=52390, tid=23299
#  assert(pos == TypeFunc::Parms + arg_cnt) failed: wrong number of arguments

Current CompileTask:
C2:   2782  924    b  4       compiler.lib.ir_framework.test.TestVM::getAnnotation (45 bytes)

Stack: [0x0000700006667000,0x0000700006767000],  sp=0x00007000067644e0,  free space=1013k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.dylib+0x1190899]  VMError::report_and_die(int, char const*, char const*, __va_list_tag*, Thread*, unsigned char*, void*, void*, char const*, int, unsigned long)+0x6e9
V  [libjvm.dylib+0x1190f1b]  VMError::report_and_die(Thread*, void*, char const*, int, char const*, char const*, __va_list_tag*)+0x3b
V  [libjvm.dylib+0x5fe96d]  report_vm_error(char const*, int, char const*, char const*, ...)+0xdd
V  [libjvm.dylib+0x11057ab]  TypeTuple::make_domain(ciMethod*, bool)+0x91b
V  [libjvm.dylib+0x111263c]  TypeFunc::make(ciMethod*, bool)+0x8c
V  [libjvm.dylib+0x82cc11]  GraphKit::record_profiled_arguments_for_speculation(ciMethod*, Bytecodes::Code)+0x31
V  [libjvm.dylib+0x6a2ff4]  Parse::do_call()+0xa54
V  [libjvm.dylib+0xed71c4]  Parse::do_one_bytecode()+0x194
V  [libjvm.dylib+0xebfbe1]  Parse::do_one_block()+0x441
V  [libjvm.dylib+0xebdb68]  Parse::do_all_blocks()+0x3f8
V  [libjvm.dylib+0xeb8dad]  Parse::Parse(JVMState*, ciMethod*, float)+0x112d
V  [libjvm.dylib+0x48207b]  ParseGenerator::generate(JVMState*)+0xab
V  [libjvm.dylib+0x59c5d3]  Compile::Compile(ciEnv*, ciMethod*, int, bool, bool, bool, bool, bool, DirectiveSet*)+0x1523
V  [libjvm.dylib+0x480599]  C2Compiler::compile_method(ciEnv*, ciMethod*, int, bool, DirectiveSet*)+0x109
V  [libjvm.dylib+0x5be252]  CompileBroker::invoke_compiler_on_method(CompileTask*)+0x7a2
V  [libjvm.dylib+0x5bd890]  CompileBroker::compiler_thread_loop()+0x2c0
V  [libjvm.dylib+0x10e12c4]  JavaThread::thread_main_inner()+0x254
V  [libjvm.dylib+0x10de137]  Thread::call_run()+0x177
V  [libjvm.dylib+0xe8e110]  thread_native_entry(Thread*)+0x150
C  [libsystem_pthread.dylib+0x6109]  _pthread_start+0x94
C  [libsystem_pthread.dylib+0x1b8b]  thread_start+0xf

Comments
The crash happens only with compiler.valhalla.inlinetypes.InlineTypes::Scenario[5]: new Scenario(5, "-XX:+IgnoreUnrecognizedVMOptions", "-XX:-UseACmpProfile", "-XX:+AlwaysIncrementalInline", "-XX:FlatArrayElementMaxOops=5", "-XX:FlatArrayElementMaxSize=-1", "-XX:-UseArrayLoadStoreProfile", "-XX:InlineFieldMaxFlatSize=-1", "-XX:-InlineTypePassFieldsAsArgs", "-XX:-InlineTypeReturnedAsFields" However, the CDS archive is dumped with InlineTypePassFieldsAsArgs==true and InlineTypeReturnedAsFields==true. So the archived version of java/util/ImmutableCollections$ListN::size() thinks that it has scalarized args. However, the compiler, looking at the runtime value of InlineTypePassFieldsAsArgs, think that size() should not have scalarized args. The fix is to refuse to load the CDS archive is such important globals do not match.
10-08-2021

The crash happens when compiling java/util/ImmutableCollections$ListN::size:"()I". For some reason, when loaded from CDS, Method::has_scalarized_args() is true. backtrace: 1 TypeTuple::make_domain 2 TypeFunc::make 3 Compile::Compile 4 C2Compiler::compile_method 5 CompileBroker::invoke_compiler_on_method 6 CompileBroker::compiler_thread_loop 7 CompilerThread::thread_entry 8 JavaThread::thread_main_inner 9 JavaThread::run 10 Thread::call_run 11 thread_native_entry 12 start_thread 13 clone Inside TypeFunc::make(): bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation; const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, false); const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, true) : domain_sig; When CDS is disabled: (gdb) p method->has_scalarized_args() $8 = false When CDS is enabled: (gdb) p method->has_scalarized_args() $37 = true As a result, TypeTuple::make_domain() is called a second time when CDS is enabled, leading up to the assert.
10-08-2021

These tests pass when running with -Xshare:off. I assign this to hotspot/compiler category for evaluation where the assertion comes from. This could be related to CDS.
10-08-2021