8229961: Assert failure in compiler/graalunit/HotspotTest.java

Reviewed-by: kvn
This commit is contained in:
Tom Rodriguez 2019-12-11 09:47:41 -08:00
parent d3f7666418
commit bca86d6492
26 changed files with 150 additions and 60 deletions

View File

@ -1356,7 +1356,7 @@ bool nmethod::make_not_entrant_or_zombie(int state) {
}
// Must happen before state change. Otherwise we have a race condition in
// nmethod::can_not_entrant_be_converted(). I.e., a method can immediately
// nmethod::can_convert_to_zombie(). I.e., a method can immediately
// transition its state from 'not_entrant' to 'zombie' without having to wait
// for stack scanning.
if (state == not_entrant) {

View File

@ -776,9 +776,9 @@ class nmethodLocker : public StackObj {
lock(_nm);
}
static void lock(CompiledMethod* method) {
static void lock(CompiledMethod* method, bool zombie_ok = false) {
if (method == NULL) return;
lock_nmethod(method);
lock_nmethod(method, zombie_ok);
}
static void unlock(CompiledMethod* method) {
@ -792,10 +792,10 @@ class nmethodLocker : public StackObj {
}
CompiledMethod* code() { return _nm; }
void set_code(CompiledMethod* new_nm) {
void set_code(CompiledMethod* new_nm, bool zombie_ok = false) {
unlock(_nm); // note: This works even if _nm==new_nm.
_nm = new_nm;
lock(_nm);
lock(_nm, zombie_ok);
}
};

View File

@ -25,6 +25,7 @@
#ifndef SHARE_JVMCI_JNIACCESSMARK_INLINE_HPP
#define SHARE_JVMCI_JNIACCESSMARK_INLINE_HPP
#include "code/nmethod.hpp"
#include "jvmci/jvmciEnv.hpp"
#include "runtime/interfaceSupport.inline.hpp"

View File

@ -980,7 +980,8 @@ C2V_VMENTRY_NULL(jobject, disassembleCodeBlob, (JNIEnv* env, jobject, jobject in
}
JVMCIObject installedCodeObject = JVMCIENV->wrap(installedCode);
CodeBlob* cb = JVMCIENV->asCodeBlob(installedCodeObject);
nmethodLocker locker;
CodeBlob* cb = JVMCIENV->get_code_blob(installedCodeObject, locker);
if (cb == NULL) {
return NULL;
}
@ -1025,7 +1026,8 @@ C2V_VMENTRY_NULL(jobject, executeHotSpotNmethod, (JNIEnv* env, jobject, jobject
HandleMark hm;
JVMCIObject nmethod_mirror = JVMCIENV->wrap(hs_nmethod);
nmethod* nm = JVMCIENV->asNmethod(nmethod_mirror);
nmethodLocker locker;
nmethod* nm = JVMCIENV->get_nmethod(nmethod_mirror, locker);
if (nm == NULL) {
JVMCI_THROW_NULL(InvalidInstalledCodeException);
}
@ -2447,7 +2449,8 @@ C2V_VMENTRY_0(jlong, translate, (JNIEnv* env, jobject, jobject obj_handle))
Handle constant = thisEnv->asConstant(obj, JVMCI_CHECK_0);
result = peerEnv->get_object_constant(constant());
} else if (thisEnv->isa_HotSpotNmethod(obj)) {
nmethod* nm = thisEnv->asNmethod(obj);
nmethodLocker locker;
nmethod* nm = JVMCIENV->get_nmethod(obj, locker);
if (nm != NULL) {
JVMCINMethodData* data = nm->jvmci_nmethod_data();
if (data != NULL) {
@ -2512,12 +2515,14 @@ C2V_VMENTRY_NULL(jobject, unhand, (JNIEnv* env, jobject, jlong obj_handle))
C2V_VMENTRY(void, updateHotSpotNmethod, (JNIEnv* env, jobject, jobject code_handle))
JVMCIObject code = JVMCIENV->wrap(code_handle);
// Execute this operation for the side effect of updating the InstalledCode state
JVMCIENV->asNmethod(code);
nmethodLocker locker;
JVMCIENV->get_nmethod(code, locker);
}
C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
JVMCIObject code = JVMCIENV->wrap(code_handle);
CodeBlob* cb = JVMCIENV->asCodeBlob(code);
nmethodLocker locker;
CodeBlob* cb = JVMCIENV->get_code_blob(code, locker);
if (cb == NULL) {
return NULL;
}

View File

@ -1476,8 +1476,8 @@ void JVMCIEnv::invalidate_nmethod_mirror(JVMCIObject mirror, JVMCI_TRAPS) {
JVMCI_THROW(NullPointerException);
}
jlong nativeMethod = get_InstalledCode_address(mirror);
nmethod* nm = JVMCIENV->asNmethod(mirror);
nmethodLocker locker;
nmethod* nm = JVMCIENV->get_nmethod(mirror, locker);
if (nm == NULL) {
// Nothing to do
return;
@ -1518,45 +1518,81 @@ ConstantPool* JVMCIEnv::asConstantPool(JVMCIObject obj) {
return *metadataHandle;
}
CodeBlob* JVMCIEnv::asCodeBlob(JVMCIObject obj) {
CodeBlob* JVMCIEnv::get_code_blob(JVMCIObject obj, nmethodLocker& locker) {
address code = (address) get_InstalledCode_address(obj);
if (code == NULL) {
return NULL;
}
if (isa_HotSpotNmethod(obj)) {
jlong compile_id_snapshot = get_HotSpotNmethod_compileIdSnapshot(obj);
if (compile_id_snapshot != 0L) {
// A HotSpotNMethod not in an nmethod's oops table so look up
// the nmethod and then update the fields based on its state.
nmethod* nm = NULL;
{
// Lookup the CodeBlob while holding the CodeCache_lock to ensure the nmethod can't be freed
// by nmethod::flush while we're interrogating it.
MutexLocker cm_lock(CodeCache_lock, Mutex::_no_safepoint_check_flag);
CodeBlob* cb = CodeCache::find_blob_unsafe(code);
if (cb == (CodeBlob*) code) {
// Found a live CodeBlob with the same address, make sure it's the same nmethod
nmethod* nm = cb->as_nmethod_or_null();
if (nm != NULL && nm->compile_id() == compile_id_snapshot) {
if (!nm->is_alive()) {
// Break the links from the mirror to the nmethod
set_InstalledCode_address(obj, 0);
set_InstalledCode_entryPoint(obj, 0);
} else if (nm->is_not_entrant()) {
// Zero the entry point so that the nmethod
// cannot be invoked by the mirror but can
// still be deoptimized.
set_InstalledCode_entryPoint(obj, 0);
}
return cb;
nmethod* the_nm = cb->as_nmethod_or_null();
if (the_nm != NULL && the_nm->is_alive()) {
// Lock the nmethod to stop any further transitions by the sweeper. It's still possible
// for this code to execute in the middle of the sweeping of the nmethod but that will be
// handled below.
locker.set_code(nm, true);
nm = the_nm;
}
}
// Clear the InstalledCode fields of this HotSpotNmethod
// that no longer refers to an nmethod in the code cache.
}
if (nm != NULL) {
// We found the nmethod but it could be in the process of being freed. Check the state of the
// nmethod while holding the CompiledMethod_lock. This ensures that any transitions by other
// threads have seen the is_locked_by_vm() update above.
MutexLocker cm_lock(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
if (!nm->is_alive()) {
// It was alive when we looked it up but it's no longer alive so release it.
locker.set_code(NULL);
nm = NULL;
}
}
jlong compile_id_snapshot = get_HotSpotNmethod_compileIdSnapshot(obj);
if (compile_id_snapshot != 0L) {
// Found a live nmethod with the same address, make sure it's the same nmethod
if (nm == (nmethod*) code && nm->compile_id() == compile_id_snapshot && nm->is_alive()) {
if (nm->is_not_entrant()) {
// Zero the entry point so that the nmethod
// cannot be invoked by the mirror but can
// still be deoptimized.
set_InstalledCode_entryPoint(obj, 0);
}
return nm;
}
// The HotSpotNmethod no longer refers to a valid nmethod so clear the state
locker.set_code(NULL);
nm = NULL;
}
if (nm == NULL) {
// The HotSpotNmethod was pointing at some nmethod but the nmethod is no longer valid, so
// clear the InstalledCode fields of this HotSpotNmethod so that it no longer refers to a
// nmethod in the code cache.
set_InstalledCode_address(obj, 0);
set_InstalledCode_entryPoint(obj, 0);
return NULL;
}
return nm;
}
return (CodeBlob*) code;
CodeBlob* cb = (CodeBlob*) code;
assert(!cb->is_nmethod(), "unexpected nmethod");
return cb;
}
nmethod* JVMCIEnv::get_nmethod(JVMCIObject obj, nmethodLocker& locker) {
CodeBlob* cb = get_code_blob(obj, locker);
if (cb != NULL) {
return cb->as_nmethod_or_null();
}
return NULL;
}
// Generate implementations for the initialize, new, isa, get and set methods for all the types and
// fields declared in the JVMCI_CLASSES_DO macro.

View File

@ -324,18 +324,13 @@ public:
void fthrow_error(const char* file, int line, const char* format, ...) ATTRIBUTE_PRINTF(4, 5);
// Given an instance of HotSpotInstalledCode return the corresponding CodeBlob*
CodeBlob* asCodeBlob(JVMCIObject code);
// Given an instance of HotSpotInstalledCode return the corresponding CodeBlob*. The
// nmethodLocker is required to keep the CodeBlob alive in the case where it's an nmethod.
CodeBlob* get_code_blob(JVMCIObject code, nmethodLocker& locker);
nmethod* asNmethod(JVMCIObject code) {
CodeBlob* cb = asCodeBlob(code);
if (cb == NULL) {
return NULL;
}
nmethod* nm = cb->as_nmethod_or_null();
guarantee(nm != NULL, "not an nmethod");
return nm;
}
// Given an instance of HotSpotInstalledCode return the corresponding nmethod. The
// nmethodLocker is required to keep the nmethod alive.
nmethod* get_nmethod(JVMCIObject code, nmethodLocker& locker);
MethodData* asMethodData(jlong metaspaceMethodData) {
return (MethodData*) (address) metaspaceMethodData;

View File

@ -32,7 +32,9 @@ import jdk.internal.org.objectweb.asm.Opcodes;
import jdk.internal.org.objectweb.asm.tree.ClassNode;
import jdk.test.lib.Utils;
import jdk.vm.ci.code.InstalledCode;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.hotspot.CompilerToVMHelper;
import jdk.vm.ci.hotspot.HotSpotNmethod;
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
import java.io.IOException;
@ -64,17 +66,10 @@ public class CTVMUtilities {
return getResolvedMethod(method.getDeclaringClass(), method);
}
public static InstalledCode getInstalledCode(String name, long address,
long entryPoint) {
return new InstalledCodeStub(name, address, entryPoint);
}
private static class InstalledCodeStub extends InstalledCode {
private InstalledCodeStub(String name, long address, long entryPoint) {
super(name);
this.address = address;
this.entryPoint = entryPoint;
}
public static InstalledCode getInstalledCode(ResolvedJavaMethod method, String name, long address, long entryPoint) {
return CompilerToVMHelper.getInstalledCode(method, name, address, entryPoint);
}
public static Map<Integer, Integer> getBciToLineNumber(Executable method) {
Map<Integer, Integer> lineNumbers = new TreeMap<>();
Class<?> aClass = method.getDeclaringClass();

View File

@ -332,4 +332,15 @@ public class CompilerToVMHelper {
public static HotSpotResolvedObjectType fromObjectClass(Class<?> theClass) {
return (HotSpotResolvedObjectType) metaAccess.lookupJavaType(theClass);
}
public static InstalledCode getInstalledCode(ResolvedJavaMethod method, String name, long address, long entryPoint) {
return new InstalledCodeStub((HotSpotResolvedJavaMethodImpl) method, name, address, entryPoint);
}
private static class InstalledCodeStub extends HotSpotNmethod {
private InstalledCodeStub(HotSpotResolvedJavaMethodImpl method, String name, long address, long entryPoint) {
super(method, name, false, 0);
this.address = address;
this.entryPoint = entryPoint;
}
}
}

View File

@ -32,6 +32,8 @@
* java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
* sun.hotspot.WhiteBox sun.hotspot.parser.DiagnosticCommand

View File

@ -33,6 +33,8 @@
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:-UseJVMCICompiler
* compiler.jvmci.compilerToVM.AsResolvedJavaMethodTest

View File

@ -28,6 +28,9 @@ import compiler.testlibrary.CompilerUtils;
import jdk.test.lib.util.Pair;
import jdk.test.lib.Utils;
import jdk.vm.ci.code.InstalledCode;
import jdk.vm.ci.meta.MetaAccessProvider;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.runtime.JVMCI;
import sun.hotspot.WhiteBox;
import sun.hotspot.code.NMethod;
@ -147,11 +150,12 @@ public class CompileCodeTestCase {
}
public InstalledCode toInstalledCode() {
MetaAccessProvider metaAccess = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess();
ResolvedJavaMethod resolvedJavaMethod = metaAccess.lookupJavaMethod(executable);
NMethod nmethod = toNMethod();
long address = nmethod == null ? 0L : nmethod.address;
long entryPoint = nmethod == null ? 0L : nmethod.entry_point;
return CTVMUtilities.getInstalledCode(
executable.getName(), address, entryPoint);
return CTVMUtilities.getInstalledCode(resolvedJavaMethod, executable.getName(), address, entryPoint);
}
@Override

View File

@ -30,8 +30,10 @@
* @modules java.base/jdk.internal.misc
* @modules java.base/jdk.internal.org.objectweb.asm
* java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
* @build sun.hotspot.WhiteBox

View File

@ -32,6 +32,8 @@
* java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox

View File

@ -32,6 +32,9 @@
* java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* -XX:-UseJVMCICompiler

View File

@ -32,6 +32,9 @@
* java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* -XX:-UseJVMCICompiler

View File

@ -33,6 +33,9 @@
* java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* -XX:-UseJVMCICompiler

View File

@ -32,6 +32,9 @@
* java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @clean compiler.jvmci.compilerToVM.*
* @compile -g DummyInterface.java
* @compile -g DummyAbstractClass.java

View File

@ -32,6 +32,9 @@
* java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* -XX:-UseJVMCICompiler

View File

@ -32,6 +32,9 @@
* java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* -XX:-UseJVMCICompiler

View File

@ -32,6 +32,8 @@
* java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox

View File

@ -32,6 +32,8 @@
* java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox

View File

@ -32,6 +32,8 @@
* java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox

View File

@ -32,6 +32,9 @@
* java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
* sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox

View File

@ -33,6 +33,9 @@
* java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* -XX:-UseJVMCICompiler

View File

@ -32,6 +32,9 @@
* java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* -XX:-UseJVMCICompiler

View File

@ -32,6 +32,8 @@
* java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime
*
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox
* @run driver ClassFileInstaller sun.hotspot.WhiteBox