8219607: Add support in Graal and AOT for hidden class

Reviewed-by: kvn
This commit is contained in:
Dean Long 2020-04-27 14:23:15 -07:00
parent 68b189ae8b
commit 03f8e6ccd8
11 changed files with 126 additions and 4 deletions

View file

@ -454,6 +454,7 @@ jdk.internal.vm.compiler_EXCLUDES += \
org.graalvm.compiler.graph.test \ org.graalvm.compiler.graph.test \
org.graalvm.compiler.hotspot.aarch64.test \ org.graalvm.compiler.hotspot.aarch64.test \
org.graalvm.compiler.hotspot.amd64.test \ org.graalvm.compiler.hotspot.amd64.test \
org.graalvm.compiler.hotspot.jdk15.test \
org.graalvm.compiler.hotspot.jdk9.test \ org.graalvm.compiler.hotspot.jdk9.test \
org.graalvm.compiler.hotspot.lir.test \ org.graalvm.compiler.hotspot.lir.test \
org.graalvm.compiler.hotspot.sparc.test \ org.graalvm.compiler.hotspot.sparc.test \

View file

@ -93,6 +93,7 @@ ifeq ($(INCLUDE_GRAAL), true)
$(SRC_DIR)/org.graalvm.compiler.graph.test/src \ $(SRC_DIR)/org.graalvm.compiler.graph.test/src \
$(SRC_DIR)/org.graalvm.compiler.hotspot.aarch64.test/src \ $(SRC_DIR)/org.graalvm.compiler.hotspot.aarch64.test/src \
$(SRC_DIR)/org.graalvm.compiler.hotspot.amd64.test/src \ $(SRC_DIR)/org.graalvm.compiler.hotspot.amd64.test/src \
$(SRC_DIR)/org.graalvm.compiler.hotspot.jdk15.test/src \
$(SRC_DIR)/org.graalvm.compiler.hotspot.jdk9.test/src \ $(SRC_DIR)/org.graalvm.compiler.hotspot.jdk9.test/src \
$(SRC_DIR)/org.graalvm.compiler.hotspot.lir.test/src \ $(SRC_DIR)/org.graalvm.compiler.hotspot.lir.test/src \
$(SRC_DIR)/org.graalvm.compiler.hotspot.sparc.test/src \ $(SRC_DIR)/org.graalvm.compiler.hotspot.sparc.test/src \

View file

@ -397,6 +397,7 @@
declare_constant(JVM_ACC_HAS_MONITOR_BYTECODES) \ declare_constant(JVM_ACC_HAS_MONITOR_BYTECODES) \
declare_constant(JVM_ACC_HAS_FINALIZER) \ declare_constant(JVM_ACC_HAS_FINALIZER) \
declare_constant(JVM_ACC_IS_CLONEABLE_FAST) \ declare_constant(JVM_ACC_IS_CLONEABLE_FAST) \
declare_constant(JVM_ACC_IS_HIDDEN_CLASS) \
declare_constant(JVM_ACC_FIELD_INTERNAL) \ declare_constant(JVM_ACC_FIELD_INTERNAL) \
declare_constant(JVM_ACC_FIELD_STABLE) \ declare_constant(JVM_ACC_FIELD_STABLE) \
declare_constant(JVM_ACC_FIELD_HAS_GENERIC_SIGNATURE) \ declare_constant(JVM_ACC_FIELD_HAS_GENERIC_SIGNATURE) \

View file

@ -0,0 +1,56 @@
/*
* Copyright (c) 2020, 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.
*/
package org.graalvm.compiler.hotspot.jdk15.test;
import org.graalvm.compiler.replacements.test.MethodSubstitutionTest;
import org.junit.Test;
import java.util.function.Supplier;
/**
* As of JDK 15 {@code java.lang.Class::isHidden()} was added.
*
* @see "https://openjdk.java.net/jeps/371"
* @see "https://bugs.openjdk.java.net/browse/JDK-8238358"
*/
public class ClassReplacementsTest extends MethodSubstitutionTest {
@SuppressWarnings("all")
public static boolean isHidden(Class<?> clazz) {
return clazz.isHidden();
}
@Test
public void testIsHidden() {
testGraph("isHidden");
Supplier<Runnable> lambda = () -> () -> System.out.println("run");
for (Class<?> c : new Class<?>[]{getClass(), Cloneable.class, int[].class, String[][].class, lambda.getClass(), lambda.get().getClass()}) {
test("isHidden", c);
}
}
}

View file

@ -299,6 +299,7 @@ public class GraalHotSpotVMConfig extends GraalHotSpotVMConfigBase {
public final int jvmAccFieldHasGenericSignature = getConstant("JVM_ACC_FIELD_HAS_GENERIC_SIGNATURE", Integer.class); public final int jvmAccFieldHasGenericSignature = getConstant("JVM_ACC_FIELD_HAS_GENERIC_SIGNATURE", Integer.class);
public final int jvmAccWrittenFlags = getConstant("JVM_ACC_WRITTEN_FLAGS", Integer.class); public final int jvmAccWrittenFlags = getConstant("JVM_ACC_WRITTEN_FLAGS", Integer.class);
public final int jvmAccSynthetic = getConstant("JVM_ACC_SYNTHETIC", Integer.class); public final int jvmAccSynthetic = getConstant("JVM_ACC_SYNTHETIC", Integer.class);
public final int jvmAccIsHiddenClass = getConstant("JVM_ACC_IS_HIDDEN_CLASS", Integer.class);
public final int jvmciCompileStateCanPostOnExceptionsOffset = getJvmciJvmtiCapabilityOffset("_jvmti_can_post_on_exceptions"); public final int jvmciCompileStateCanPostOnExceptionsOffset = getJvmciJvmtiCapabilityOffset("_jvmti_can_post_on_exceptions");
public final int jvmciCompileStateCanPopFrameOffset = getJvmciJvmtiCapabilityOffset("_jvmti_can_pop_frame"); public final int jvmciCompileStateCanPopFrameOffset = getJvmciJvmtiCapabilityOffset("_jvmti_can_pop_frame");

View file

@ -285,6 +285,10 @@ public class HotSpotGraphBuilderPlugins {
r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "isPrimitive", Receiver.class); r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "isPrimitive", Receiver.class);
r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "getSuperclass", Receiver.class); r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "getSuperclass", Receiver.class);
if (config.jvmAccIsHiddenClass != 0) {
r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "isHidden", Receiver.class);
}
if (config.getFieldOffset("ArrayKlass::_component_mirror", Integer.class, "oop", Integer.MAX_VALUE) != Integer.MAX_VALUE) { if (config.getFieldOffset("ArrayKlass::_component_mirror", Integer.class, "oop", Integer.MAX_VALUE) != Integer.MAX_VALUE) {
r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "getComponentType", Receiver.class); r.registerMethodSubstitution(HotSpotClassSubstitutions.class, "getComponentType", Receiver.class);
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -31,6 +31,7 @@ import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.KLASS_MODIFIER_FLAGS_LOCATION; import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.KLASS_MODIFIER_FLAGS_LOCATION;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.KLASS_SUPER_KLASS_LOCATION; import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.KLASS_SUPER_KLASS_LOCATION;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayKlassComponentMirrorOffset; import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayKlassComponentMirrorOffset;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.jvmAccIsHiddenClass;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.klassAccessFlagsOffset; import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.klassAccessFlagsOffset;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.klassIsArray; import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.klassIsArray;
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.klassModifierFlagsOffset; import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.klassModifierFlagsOffset;
@ -80,6 +81,18 @@ public class HotSpotClassSubstitutions {
} }
} }
@MethodSubstitution(isStatic = false, optional = true)
public static boolean isHidden(final Class<?> thisObj) {
KlassPointer klass = ClassGetHubNode.readClass(thisObj);
if (klass.isNull()) {
// Class for primitive type
return false;
} else {
int accessFlags = klass.readInt(klassAccessFlagsOffset(INJECTED_VMCONFIG), KLASS_ACCESS_FLAGS_LOCATION);
return (accessFlags & (jvmAccIsHiddenClass(INJECTED_VMCONFIG))) != 0;
}
}
@MethodSubstitution(isStatic = false) @MethodSubstitution(isStatic = false)
public static boolean isArray(final Class<?> thisObj) { public static boolean isArray(final Class<?> thisObj) {
KlassPointer klass = ClassGetHubNode.readClass(thisObj); KlassPointer klass = ClassGetHubNode.readClass(thisObj);

View file

@ -361,6 +361,11 @@ public class HotSpotReplacementsUtil {
return config.jvmAccWrittenFlags; return config.jvmAccWrittenFlags;
} }
@Fold
public static int jvmAccIsHiddenClass(@InjectedParameter GraalHotSpotVMConfig config) {
return config.jvmAccIsHiddenClass;
}
public static final LocationIdentity KLASS_LAYOUT_HELPER_LOCATION = new HotSpotOptimizingLocationIdentity("Klass::_layout_helper") { public static final LocationIdentity KLASS_LAYOUT_HELPER_LOCATION = new HotSpotOptimizingLocationIdentity("Klass::_layout_helper") {
@Override @Override
public ValueNode canonicalizeRead(ValueNode read, AddressNode location, ValueNode object, CanonicalizerTool tool) { public ValueNode canonicalizeRead(ValueNode read, AddressNode location, ValueNode object, CanonicalizerTool tool) {

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
@ -242,5 +242,4 @@ org.graalvm.compiler.core.test.deopt.CompiledMethodTest 8202955
org.graalvm.compiler.hotspot.test.ReservedStackAccessTest 8213567 windows-all org.graalvm.compiler.hotspot.test.ReservedStackAccessTest 8213567 windows-all
org.graalvm.compiler.hotspot.test.CheckGraalIntrinsics 8219607 generic-all org.graalvm.compiler.hotspot.test.LambdaStableNameTest 8243381 generic-all
org.graalvm.compiler.hotspot.test.LambdaStableNameTest 8219607 generic-all

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2018, 2020, 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
* @summary
* @requires vm.jvmci
*
* @modules jdk.internal.vm.compiler
*
* @library /test/lib /compiler/graalunit /
*
* @build compiler.graalunit.common.GraalUnitTestLauncher
*
* @run driver jdk.test.lib.FileInstaller ../../ProblemList-graal.txt ExcludeList.txt
*
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI compiler.graalunit.common.GraalUnitTestLauncher -prefix org.graalvm.compiler.hotspot.jdk15.test -exclude ExcludeList.txt
*/
/* DO NOT MODIFY THIS FILE. GENERATED BY generateTests.sh */

View file

@ -15,6 +15,7 @@ Hotspot org.graalvm.compiler.hotspot.test
HotspotAarch64 org.graalvm.compiler.hotspot.aarch64.test HotspotAarch64 org.graalvm.compiler.hotspot.aarch64.test
HotspotAmd64 org.graalvm.compiler.hotspot.amd64.test HotspotAmd64 org.graalvm.compiler.hotspot.amd64.test
HotspotJdk9 org.graalvm.compiler.hotspot.jdk9.test --vmargs --add-opens=java.base/java.lang=ALL-UNNAMED HotspotJdk9 org.graalvm.compiler.hotspot.jdk9.test --vmargs --add-opens=java.base/java.lang=ALL-UNNAMED
HotspotJdk15 org.graalvm.compiler.hotspot.jdk15.test
HotspotSparc org.graalvm.compiler.hotspot.sparc.test --requires vm.simpleArch=="sparcv9" HotspotSparc org.graalvm.compiler.hotspot.sparc.test --requires vm.simpleArch=="sparcv9"
HotspotLir org.graalvm.compiler.hotspot.lir.test HotspotLir org.graalvm.compiler.hotspot.lir.test
Loop org.graalvm.compiler.loop.test Loop org.graalvm.compiler.loop.test