Permalink
Browse files

Avoid reflection when allocating P6opaque.

  • Loading branch information...
jnthn committed Jun 11, 2013
1 parent b06dc41 commit 080f0bf24d1a4c5026855444472e6e0489aa1e83
@@ -127,10 +127,14 @@ public void compose(ThreadContext tc, STable st, SixModelObject repr_info_hash)
/* Provided we have attributes, generate the JVM backing type. If not,
* P6OpaqueBaseInstance will do. */
if (attrInfoList.size() > 0)
if (attrInfoList.size() > 0) {
generateJVMType(tc, st, attrInfoList);
else
}
else {
((P6OpaqueREPRData)st.REPRData).jvmClass = P6OpaqueBaseInstance.class;
((P6OpaqueREPRData)st.REPRData).instance = new P6OpaqueBaseInstance();
((P6OpaqueREPRData)st.REPRData).instance.st = st;
}
}
/* Adds delegation, needed for mixin support. */
@@ -511,6 +515,13 @@ private void generateJVMType(ThreadContext tc, STable st, List<AttrInfo> attrInf
// } catch (IOException e) {
// }
((P6OpaqueREPRData)st.REPRData).jvmClass = new ByteClassLoader(classCompiled).findClass(className);
try {
((P6OpaqueREPRData)st.REPRData).instance = (P6OpaqueBaseInstance)((P6OpaqueREPRData)st.REPRData).jvmClass.newInstance();
}
catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
((P6OpaqueREPRData)st.REPRData).instance.st = st;
}
private void generateDelegateMethod(ThreadContext tc, ClassWriter cw, String className, String field, String methodName) {
@@ -524,15 +535,7 @@ private void generateDelegateMethod(ThreadContext tc, ClassWriter cw, String cla
}
public SixModelObject allocate(ThreadContext tc, STable st) {
try {
P6OpaqueBaseInstance obj = (P6OpaqueBaseInstance)((P6OpaqueREPRData)st.REPRData).jvmClass.newInstance();
obj.st = st;
return obj;
}
catch (Exception e)
{
throw new RuntimeException(e);
}
return ((P6OpaqueREPRData)st.REPRData).instance.instClone();
}
public void change_type(ThreadContext tc, SixModelObject obj, SixModelObject newType) {
@@ -705,7 +708,14 @@ else if (nameToHintObject instanceof VMHashInstance) {
info.hasAutoVivContainer = REPRData.autoVivContainers[i] != null;
attrInfoList.add(info);
}
generateJVMType(tc, st, attrInfoList);
if (numAttributes > 0) {
generateJVMType(tc, st, attrInfoList);
}
else {
((P6OpaqueREPRData)st.REPRData).jvmClass = P6OpaqueBaseInstance.class;
((P6OpaqueREPRData)st.REPRData).instance = new P6OpaqueBaseInstance();
((P6OpaqueREPRData)st.REPRData).instance.st = st;
}
}
public void serialize_repr_data(ThreadContext tc, STable st, SerializationWriter writer) {
@@ -763,8 +773,7 @@ public void deserialize_finish(ThreadContext tc, STable st,
SerializationReader reader, SixModelObject stub) {
try {
// Create instance that we'll deserialize into.
P6OpaqueBaseInstance obj = (P6OpaqueBaseInstance)((P6OpaqueREPRData)st.REPRData).jvmClass.newInstance();
obj.st = st;
P6OpaqueBaseInstance obj = (P6OpaqueBaseInstance)((P6OpaqueREPRData)st.REPRData).instance.instClone();
// Install it as the stub's delegate.
((P6OpaqueDelegateInstance)stub).delegate = obj;
@@ -781,7 +790,7 @@ public void deserialize_finish(ThreadContext tc, STable st,
}
}
}
catch (IllegalAccessException | NoSuchFieldException | InstantiationException e)
catch (IllegalAccessException | NoSuchFieldException e)
{
throw new RuntimeException(e);
}
@@ -45,6 +45,14 @@ public SixModelObject clone(ThreadContext tc) {
}
}
public SixModelObject instClone() {
try {
return (SixModelObject)this.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
public void badNative() {
throw new RuntimeException("Cannot access a reference attribute as a native attribute");
}
@@ -12,6 +12,11 @@
*/
public Class<?> jvmClass;
/**
* Instance of jvmClass, cloned per allocation.
*/
public P6OpaqueBaseInstance instance;
/**
* List of class handles that have attributes in this type.
*/

0 comments on commit 080f0bf

Please sign in to comment.