Mercurial > hg > graal-jvmci-8
changeset 23673:7ef84c807bfe
8159010: [JVMCI] crashes with class redefinition
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Tue, 07 Jun 2016 17:45:03 -0700 |
parents | 480da86e95e9 |
children | 09a536b9233c |
files | jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantPool.java jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIMetaAccessContext.java jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/MetaspaceWrapperObject.java |
diffstat | 4 files changed, 47 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantPool.java Mon Jun 06 12:41:03 2016 -0700 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantPool.java Tue Jun 07 17:45:03 2016 -0700 @@ -196,7 +196,9 @@ */ @SuppressWarnings("unused") private static HotSpotConstantPool fromMetaspace(long metaspaceConstantPool) { - return new HotSpotConstantPool(metaspaceConstantPool); + HotSpotConstantPool cp = new HotSpotConstantPool(metaspaceConstantPool); + runtime().metaAccessContext.add(cp); + return cp; } private HotSpotConstantPool(long metaspaceConstantPool) {
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIMetaAccessContext.java Mon Jun 06 12:41:03 2016 -0700 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIMetaAccessContext.java Tue Jun 07 17:45:03 2016 -0700 @@ -135,6 +135,7 @@ */ metadataRoots = list.getHead(); } + assert isRegistered(metaspaceObject); } protected ResolvedJavaType createClass(Class<?> javaClass) { @@ -208,7 +209,7 @@ ChunkIterator() { currentChunk = head; currentIndex = -1; - findNext(); + next = findNext(); } Object[] currentChunk; @@ -245,4 +246,13 @@ } } + + synchronized boolean isRegistered(MetaspaceWrapperObject wrapper) { + for (WeakReference<MetaspaceWrapperObject> m : list) { + if (m != null && m.get() == wrapper) { + return true; + } + } + return false; + } }
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java Mon Jun 06 12:41:03 2016 -0700 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java Tue Jun 07 17:45:03 2016 -0700 @@ -132,10 +132,20 @@ return UNSAFE.getInt(javaClass, (long) config().klassOffset) & 0xFFFFFFFFL; } + @Override public long getMetaspacePointer() { return getMetaspaceKlass(); } + /** + * The Klass* for this object is kept alive by the direct reference to {@link #javaClass} so no + * extra work is required. + */ + @Override + public boolean isRegistered() { + return true; + } + @Override public int getModifiers() { if (isArray()) { @@ -429,7 +439,13 @@ } public HotSpotConstantPool getConstantPool() { - if (constantPool == null) { + if (constantPool == null || !isArray() && UNSAFE.getAddress(getMetaspaceKlass() + config().instanceKlassConstantsOffset) != constantPool.getMetaspaceConstantPool()) { + /* + * If the pointer to the ConstantPool has changed since this was last read refresh the + * HotSpotConstantPool wrapper object. This ensures that uses of the constant pool are + * operating on the latest one and that HotSpotResolvedJavaMethodImpls will be able to + * use the shared copy instead of creating their own instance. + */ constantPool = compilerToVM().getConstantPool(this, config().instanceKlassConstantsOffset); } return constantPool;
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/MetaspaceWrapperObject.java Mon Jun 06 12:41:03 2016 -0700 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/MetaspaceWrapperObject.java Tue Jun 07 17:45:03 2016 -0700 @@ -23,7 +23,8 @@ package jdk.vm.ci.hotspot; /** - * A tag interface indicating that this type is a wrapper around a HotSpot metaspace object. + * A tag interface indicating that this type is a wrapper around a HotSpot metaspace object that + * requires GC interaction to keep alive. * * It would preferable if this were the base class containing the pointer but that would require * mixins since most of the wrapper types have complex supertype hierarchies. @@ -31,4 +32,18 @@ interface MetaspaceWrapperObject { long getMetaspacePointer(); + + /** + * Check if this object is properly registered for metadata tracking. All classes which + * implement this interface must be registered with the + * {@link HotSpotJVMCIMetaAccessContext#add} unless they are kept alive through other means. + * Currently the only type which doesn't require explicit registration is + * {@link HotSpotResolvedObjectTypeImpl} since it's kept alive by references to the + * {@link Class}. + * + * @return true if this object is properly registered for meta data tracking. + */ + default boolean isRegistered() { + return HotSpotJVMCIRuntime.runtime().metaAccessContext.isRegistered(this); + } }