Merge pull request #513 from dicej/lambda-fixes

fix a few memory safety issues
This commit is contained in:
Joel Dice 2016-12-07 21:39:16 -07:00 committed by GitHub
commit c545e3dde2
4 changed files with 35 additions and 9 deletions

View File

@ -11,6 +11,11 @@
package java.lang.invoke; package java.lang.invoke;
public class SerializedLambda implements java.io.Serializable { public class SerializedLambda implements java.io.Serializable {
public Object getCapturedArg(int i) {
// todo
return null;
}
public int getImplMethodKind() { public int getImplMethodKind() {
// todo // todo
return 0; return 0;

View File

@ -268,6 +268,7 @@ class MyThread : public Thread {
heapImage(0), heapImage(0),
codeImage(0), codeImage(0),
thunkTable(0), thunkTable(0),
dynamicTable(0),
trace(0), trace(0),
reference(0), reference(0),
arch(parent ? parent->arch : avian::codegen::makeArchitectureNative( arch(parent ? parent->arch : avian::codegen::makeArchitectureNative(
@ -1310,6 +1311,10 @@ Allocator* allocator(MyThread* t);
unsigned addDynamic(MyThread* t, GcInvocation* invocation) unsigned addDynamic(MyThread* t, GcInvocation* invocation)
{ {
if (t->dynamicTable == nullptr) {
t->dynamicTable = dynamicTable(t);
}
ACQUIRE(t, t->m->classLock); ACQUIRE(t, t->m->classLock);
int index = invocation->index(); int index = invocation->index();
@ -5177,13 +5182,18 @@ loop:
jclass lmfClass = e->vtable->FindClass( jclass lmfClass = e->vtable->FindClass(
e, "java/lang/invoke/LambdaMetafactory"); e, "java/lang/invoke/LambdaMetafactory");
jmethodID makeLambda = e->vtable->GetStaticMethodID( jmethodID makeLambda
e, = e->vtable->GetStaticMethodID(e,
lmfClass, lmfClass,
"makeLambda", "makeLambda",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/" "(Ljava/lang/String;"
"String;Ljava/" "Ljava/lang/String;"
"lang/String;Ljava/lang/String;Ljava/lang/String;I)[B"); "Ljava/lang/String;"
"Ljava/lang/String;"
"Ljava/lang/String;"
"Ljava/lang/String;"
"I"
")[B");
GcReference* reference = cast<GcReference>( GcReference* reference = cast<GcReference>(
t, t,

View File

@ -1075,7 +1075,7 @@ unsigned parsePoolEntry(Thread* t,
returnCode, returnCode,
parameterCount, parameterCount,
parameterFootprint, parameterFootprint,
0, ACC_STATIC,
0, 0,
0, 0,
0, 0,
@ -6076,6 +6076,8 @@ GcCallSite* resolveDynamic(Thread* t, GcInvocation* invocation)
array->setBodyElement(t, argument++, name); array->setBodyElement(t, argument++, name);
array->setBodyElement(t, argument++, type); array->setBodyElement(t, argument++, type);
THREAD_RUNTIME_ARRAY(t, char, specBuffer, bootstrap->spec()->length());
const char* spec; const char* spec;
GcArray* argArray = array; GcArray* argArray = array;
PROTECT(t, argArray); PROTECT(t, argArray);
@ -6101,7 +6103,10 @@ GcCallSite* resolveDynamic(Thread* t, GcInvocation* invocation)
"[Ljava/lang/invoke/MethodType;" "[Ljava/lang/invoke/MethodType;"
")Ljava/lang/invoke/CallSite;"; ")Ljava/lang/invoke/CallSite;";
} else if (bootstrap->parameterCount() == 2 + bootstrapArray->length()) { } else if (bootstrap->parameterCount() == 2 + bootstrapArray->length()) {
spec = reinterpret_cast<char*>(bootstrap->spec()->body().begin()); memcpy(RUNTIME_ARRAY_BODY(specBuffer),
bootstrap->spec()->body().begin(),
bootstrap->spec()->length());
spec = RUNTIME_ARRAY_BODY(specBuffer);
} else { } else {
abort(t); abort(t);
} }

View File

@ -56,5 +56,11 @@ public class InvokeDynamic {
expect(s.get().first == 42L); expect(s.get().first == 42L);
expect(s.get().second == 77.1D); expect(s.get().second == 77.1D);
} }
{ double[] a = new double[] { 3.14D };
Supplier<Pair<Long, Double>> s = () -> new Pair<Long, Double>(42L, a[0]);
expect(s.get().first == 42L);
expect(s.get().second == 3.14D);
}
} }
} }