Skip to content
Permalink
Browse files
8275670: ciReplay: java.lang.NoClassDefFoundError when trying to load…
… java/lang/invoke/LambdaForm$MH

Reviewed-by: kvn, chagedorn
  • Loading branch information
dean-long committed Nov 4, 2021
1 parent 81203ef commit dcf36f87f87d52490c1f0434c2fca99fc8fd90a2
Showing with 115 additions and 26 deletions.
  1. +31 −24 src/hotspot/share/ci/ciEnv.cpp
  2. +2 −2 src/hotspot/share/ci/ciEnv.hpp
  3. +82 −0 test/hotspot/jtreg/compiler/ciReplay/TestLambdas.java
@@ -1443,14 +1443,22 @@ void ciEnv::record_mh(Thread* thread, oop mh) {
RecordLocation fp(this, "member");
record_member(thread, member);
} else {
// Check <MethodHandle subclass>.argL0 field
// Probably BoundMethodHandle.Species_L, but we only care if the field exists
oop arg = obj_field(mh, "argL0");
if (arg != NULL) {
RecordLocation fp(this, "argL0");
if (arg->klass()->is_instance_klass()) {
InstanceKlass* ik2 = InstanceKlass::cast(arg->klass());
record_best_dyno_loc(ik2);
// Check <MethodHandle subclass>.argL<n> fields
// Probably BoundMethodHandle.Species_L*, but we only care if the field exists
char arg_name[] = "argLXX";
int max_arg = 99;
for (int index = 0; index <= max_arg; ++index) {
jio_snprintf(arg_name, sizeof (arg_name), "argL%d", index);
oop arg = obj_field(mh, arg_name);
if (arg != NULL) {
RecordLocation fp(this, "%s", arg_name);
if (arg->klass()->is_instance_klass()) {
InstanceKlass* ik2 = InstanceKlass::cast(arg->klass());
record_best_dyno_loc(ik2);
record_call_site_obj(thread, arg);
}
} else {
break;
}
}
}
@@ -1459,13 +1467,13 @@ void ciEnv::record_mh(Thread* thread, oop mh) {
// Process an object found at an invokedynamic/invokehandle call site and record any dynamic locations.
// Types currently supported are MethodHandle and CallSite.
// The object is typically the "appendix" object, or Bootstrap Method (BSM) object.
void ciEnv::record_call_site_obj(Thread* thread, const constantPoolHandle& pool, const Handle obj)
void ciEnv::record_call_site_obj(Thread* thread, oop obj)
{
if (obj.not_null()) {
if (java_lang_invoke_MethodHandle::is_instance(obj())) {
record_mh(thread, obj());
} else if (java_lang_invoke_ConstantCallSite::is_instance(obj())) {
oop target = java_lang_invoke_CallSite::target(obj());
if (obj != NULL) {
if (java_lang_invoke_MethodHandle::is_instance(obj)) {
record_mh(thread, obj);
} else if (java_lang_invoke_ConstantCallSite::is_instance(obj)) {
oop target = java_lang_invoke_CallSite::target(obj);
if (target->klass()->is_instance_klass()) {
RecordLocation fp(this, "target");
InstanceKlass* ik = InstanceKlass::cast(target->klass());
@@ -1476,7 +1484,7 @@ void ciEnv::record_call_site_obj(Thread* thread, const constantPoolHandle& pool,
}

// Process an adapter Method* found at an invokedynamic/invokehandle call site and record any dynamic locations.
void ciEnv::record_call_site_method(Thread* thread, const constantPoolHandle& pool, Method* adapter) {
void ciEnv::record_call_site_method(Thread* thread, Method* adapter) {
InstanceKlass* holder = adapter->method_holder();
if (!holder->is_hidden()) {
return;
@@ -1491,21 +1499,20 @@ void ciEnv::process_invokedynamic(const constantPoolHandle &cp, int indy_index,
if (cp_cache_entry->is_resolved(Bytecodes::_invokedynamic)) {
// process the adapter
Method* adapter = cp_cache_entry->f1_as_method();
record_call_site_method(thread, cp, adapter);
record_call_site_method(thread, adapter);
// process the appendix
Handle appendix(thread, cp_cache_entry->appendix_if_resolved(cp));
oop appendix = cp_cache_entry->appendix_if_resolved(cp);
{
RecordLocation fp(this, "<appendix>");
record_call_site_obj(thread, cp, appendix);
record_call_site_obj(thread, appendix);
}
// process the BSM
int pool_index = cp_cache_entry->constant_pool_index();
BootstrapInfo bootstrap_specifier(cp, pool_index, indy_index);
oop bsm_oop = cp->resolve_possibly_cached_constant_at(bootstrap_specifier.bsm_index(), thread);
Handle bsm(thread, bsm_oop);
oop bsm = cp->resolve_possibly_cached_constant_at(bootstrap_specifier.bsm_index(), thread);
{
RecordLocation fp(this, "<bsm>");
record_call_site_obj(thread, cp, bsm);
record_call_site_obj(thread, bsm);
}
}
}
@@ -1523,12 +1530,12 @@ void ciEnv::process_invokehandle(const constantPoolHandle &cp, int index, JavaTh
if (cp_cache_entry->is_resolved(Bytecodes::_invokehandle)) {
// process the adapter
Method* adapter = cp_cache_entry->f1_as_method();
Handle appendix(thread, cp_cache_entry->appendix_if_resolved(cp));
record_call_site_method(thread, cp, adapter);
oop appendix = cp_cache_entry->appendix_if_resolved(cp);
record_call_site_method(thread, adapter);
// process the appendix
{
RecordLocation fp(this, "<appendix>");
record_call_site_obj(thread, cp, appendix);
record_call_site_obj(thread, appendix);
}
}
}
@@ -508,8 +508,8 @@ class ciEnv : StackObj {
void record_lambdaform(Thread* thread, oop obj);
void record_member(Thread* thread, oop obj);
void record_mh(Thread* thread, oop obj);
void record_call_site_obj(Thread* thread, const constantPoolHandle& pool, const Handle appendix);
void record_call_site_method(Thread* thread, const constantPoolHandle& pool, Method* adapter);
void record_call_site_obj(Thread* thread, oop obj);
void record_call_site_method(Thread* thread, Method* adapter);
void process_invokedynamic(const constantPoolHandle &cp, int index, JavaThread* thread);
void process_invokehandle(const constantPoolHandle &cp, int index, JavaThread* thread);
void find_dynamic_call_sites();
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/**
* @test
* @bug 8275670
* @library / /test/lib
* @summary testing of ciReplay with inlining
* @requires vm.flightRecorder != true & vm.compMode != "Xint" & vm.debug == true & vm.compiler2.enabled
* @modules java.base/jdk.internal.misc
* @build sun.hotspot.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* compiler.ciReplay.TestLambdas
*/

package compiler.ciReplay;

public class TestLambdas extends CiReplayBase {
public static void main(String args[]) {
new TestLambdas().runTest(false, TIERED_DISABLED_VM_OPTION);
}

@Override
public void testAction() {
positiveTest(TIERED_DISABLED_VM_OPTION);
}

@Override
public String getTestClass() {
return Test.class.getName();
}
}

class Test {
public static void main(String[] args) {
for (int i = 0; i < 20_000; i++) {
test(i);
}
}

static void test(int i) {
concat_lambdas();
}


// Create nested BoundMethodHandle using StringConcatHelper
static boolean concat_lambdas() {
String source = "0123456789abcdefgABCDEFG";
String result = "";

int max = 10;
for (int cp = 0; cp < max; ++cp) {
String regex = new String(Character.toChars(cp));
result = source.substring(0, 3) + regex
+ source.substring(3, 9) + regex
+ source.substring(9, 15) + regex
+ source.substring(15);
}
return result.equals("xyzzy");
}
}

1 comment on commit dcf36f8

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on dcf36f8 Nov 4, 2021

Please sign in to comment.