This commit is contained in:
Tom Rodriguez 2016-05-03 21:28:46 +00:00
commit 0091cd268a
6 changed files with 45 additions and 0 deletions

View File

@ -882,4 +882,9 @@ final class HotSpotResolvedObjectTypeImpl extends HotSpotResolvedJavaType implem
public boolean isTrustedInterfaceType() {
return TrustedInterface.class.isAssignableFrom(mirror());
}
@Override
public boolean isCloneableWithAllocation() {
return (getAccessFlags() & config().jvmAccIsCloneableFast) != 0;
}
}

View File

@ -267,4 +267,9 @@ public final class HotSpotResolvedPrimitiveType extends HotSpotResolvedJavaType
public boolean isTrustedInterfaceType() {
return false;
}
@Override
public boolean isCloneableWithAllocation() {
return false;
}
}

View File

@ -1077,6 +1077,7 @@ public class HotSpotVMConfig {
@HotSpotVMConstant(name = "JVM_ACC_FIELD_STABLE") @Stable public int jvmAccFieldStable;
@HotSpotVMConstant(name = "JVM_ACC_FIELD_HAS_GENERIC_SIGNATURE") @Stable public int jvmAccFieldHasGenericSignature;
@HotSpotVMConstant(name = "JVM_ACC_WRITTEN_FLAGS") @Stable public int jvmAccWrittenFlags;
@HotSpotVMConstant(name = "JVM_ACC_IS_CLONEABLE_FAST") @Stable public int jvmAccIsCloneableFast;
// Modifier.SYNTHETIC is not public so we get it via vmStructs.
@HotSpotVMConstant(name = "JVM_ACC_SYNTHETIC") @Stable public int jvmAccSynthetic;

View File

@ -359,4 +359,12 @@ public interface ResolvedJavaType extends JavaType, ModifiersProvider {
}
return null;
}
/**
* Returns true if this type is {@link Cloneable} and can be safely cloned by creating a normal
* Java allocation and populating it from the fields returned by
* {@link #getInstanceFields(boolean)}. Some types may require special handling by the platform
* so they would to go through the normal {@link Object#clone} path.
*/
boolean isCloneableWithAllocation();
}

View File

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

View File

@ -866,6 +866,31 @@ public class TestResolvedJavaType extends TypeUniverse {
}
}
static class TrivialCloneable implements Cloneable {
@Override
protected Object clone() {
return new TrivialCloneable();
}
}
@Test
public void isCloneableWithAllocationTest() {
ResolvedJavaType cloneable = metaAccess.lookupJavaType(Cloneable.class);
for (Class<?> c : classes) {
ResolvedJavaType type = metaAccess.lookupJavaType(c);
if (type.isCloneableWithAllocation()) {
// Only Cloneable types should be allocation cloneable
assertTrue(c.toString(), cloneable.isAssignableFrom(type));
}
}
/*
* We can't know for sure which types should be allocation cloneable on a particular
* platform but assume that at least totally trivial objects should be.
*/
ResolvedJavaType trivialCloneable = metaAccess.lookupJavaType(TrivialCloneable.class);
assertTrue(trivialCloneable.toString(), trivialCloneable.isCloneableWithAllocation());
}
@Test
public void findMethodTest() {
try {