use of com.oracle.truffle.espresso.classfile.RuntimeConstantPool in project graal by oracle.
the class VM method computeEnclosingClass.
/**
* Return the enclosing class; or null for: primitives, arrays, anonymous classes (declared
* inside methods).
*/
private static Klass computeEnclosingClass(ObjectKlass klass) {
InnerClassesAttribute innerClasses = (InnerClassesAttribute) klass.getAttribute(InnerClassesAttribute.NAME);
if (innerClasses == null) {
return null;
}
RuntimeConstantPool pool = klass.getConstantPool();
boolean found = false;
Klass outerKlass = null;
for (InnerClassesAttribute.Entry entry : innerClasses.entries()) {
if (entry.innerClassIndex != 0) {
Symbol<Name> innerDescriptor = pool.classAt(entry.innerClassIndex).getName(pool);
// Check decriptors/names before resolving.
if (innerDescriptor.equals(klass.getName())) {
Klass innerKlass = pool.resolvedKlassAt(klass, entry.innerClassIndex);
found = (innerKlass == klass);
if (found && entry.outerClassIndex != 0) {
outerKlass = pool.resolvedKlassAt(klass, entry.outerClassIndex);
}
}
}
if (found) {
break;
}
}
// the system could allow a spoof of an inner class to gain access rights.
return outerKlass;
}
use of com.oracle.truffle.espresso.classfile.RuntimeConstantPool in project graal by oracle.
the class VM method JVM_GetDeclaredClasses.
@VmImpl(isJni = true)
@JavaType(Class[].class)
public StaticObject JVM_GetDeclaredClasses(@JavaType(Class.class) StaticObject self) {
Meta meta = getMeta();
Klass klass = self.getMirrorKlass();
if (klass.isPrimitive() || klass.isArray()) {
return meta.java_lang_Class.allocateReferenceArray(0);
}
ObjectKlass instanceKlass = (ObjectKlass) klass;
InnerClassesAttribute innerClasses = (InnerClassesAttribute) instanceKlass.getAttribute(InnerClassesAttribute.NAME);
if (innerClasses == null || innerClasses.entries().length == 0) {
return meta.java_lang_Class.allocateReferenceArray(0);
}
RuntimeConstantPool pool = instanceKlass.getConstantPool();
List<Klass> innerKlasses = new ArrayList<>();
for (InnerClassesAttribute.Entry entry : innerClasses.entries()) {
if (entry.innerClassIndex != 0 && entry.outerClassIndex != 0) {
// Check to see if the name matches the class we're looking for
// before attempting to find the class.
Symbol<Name> outerDescriptor = pool.classAt(entry.outerClassIndex).getName(pool);
// Check decriptors/names before resolving.
if (outerDescriptor.equals(instanceKlass.getName())) {
Klass outerKlass = pool.resolvedKlassAt(instanceKlass, entry.outerClassIndex);
if (outerKlass == instanceKlass) {
Klass innerKlass = pool.resolvedKlassAt(instanceKlass, entry.innerClassIndex);
// HotSpot:
// Throws an exception if outer klass has not declared k as
// an inner klass
// Reflection::check_for_inner_class(k, inner_klass, true, CHECK_NULL);
// TODO(peterssen): The check in HotSpot is redundant.
innerKlasses.add(innerKlass);
}
}
}
}
return meta.java_lang_Class.allocateReferenceArray(innerKlasses.size(), new IntFunction<StaticObject>() {
@Override
public StaticObject apply(int index) {
return innerKlasses.get(index).mirror();
}
});
}
use of com.oracle.truffle.espresso.classfile.RuntimeConstantPool in project graal by oracle.
the class VM method JVM_GetPermittedSubclasses.
@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(Class[].class)
public StaticObject JVM_GetPermittedSubclasses(@JavaType(Class.class) StaticObject self) {
Klass k = self.getMirrorKlass();
if (!(k instanceof ObjectKlass)) {
return StaticObject.NULL;
}
ObjectKlass klass = (ObjectKlass) k;
if (!klass.isSealed()) {
return StaticObject.NULL;
}
char[] classes = ((PermittedSubclassesAttribute) klass.getAttribute(PermittedSubclassesAttribute.NAME)).getClasses();
StaticObject[] permittedSubclasses = new StaticObject[classes.length];
RuntimeConstantPool pool = klass.getConstantPool();
int nClasses = 0;
for (int index : classes) {
Klass permitted;
try {
permitted = pool.resolvedKlassAt(klass, index);
} catch (EspressoException e) {
/* Suppress and continue */
continue;
}
if (permitted instanceof ObjectKlass) {
permittedSubclasses[nClasses++] = permitted.mirror();
}
}
if (nClasses == permittedSubclasses.length) {
return StaticObject.createArray(getMeta().java_lang_Class_array, permittedSubclasses);
}
return getMeta().java_lang_Class.allocateReferenceArray(nClasses, (i) -> permittedSubclasses[i]);
}
use of com.oracle.truffle.espresso.classfile.RuntimeConstantPool in project graal by oracle.
the class BytecodeNode method putPoolConstant.
private void putPoolConstant(VirtualFrame frame, int top, char cpi, int opcode) {
assert opcode == LDC || opcode == LDC_W || opcode == LDC2_W;
RuntimeConstantPool pool = getConstantPool();
PoolConstant constant = pool.at(cpi);
if (constant instanceof IntegerConstant) {
assert opcode == LDC || opcode == LDC_W;
putInt(frame, top, ((IntegerConstant) constant).value());
} else if (constant instanceof LongConstant) {
assert opcode == LDC2_W;
putLong(frame, top, ((LongConstant) constant).value());
} else if (constant instanceof DoubleConstant) {
assert opcode == LDC2_W;
putDouble(frame, top, ((DoubleConstant) constant).value());
} else if (constant instanceof FloatConstant) {
assert opcode == LDC || opcode == LDC_W;
putFloat(frame, top, ((FloatConstant) constant).value());
} else if (constant instanceof StringConstant) {
assert opcode == LDC || opcode == LDC_W;
StaticObject internedString = pool.resolvedStringAt(cpi);
putObject(frame, top, internedString);
} else if (constant instanceof ClassConstant) {
assert opcode == LDC || opcode == LDC_W;
Klass klass = pool.resolvedKlassAt(getDeclaringKlass(), cpi);
putObject(frame, top, klass.mirror());
} else if (constant instanceof MethodHandleConstant) {
assert opcode == LDC || opcode == LDC_W;
StaticObject methodHandle = pool.resolvedMethodHandleAt(getDeclaringKlass(), cpi);
putObject(frame, top, methodHandle);
} else if (constant instanceof MethodTypeConstant) {
assert opcode == LDC || opcode == LDC_W;
StaticObject methodType = pool.resolvedMethodTypeAt(getDeclaringKlass(), cpi);
putObject(frame, top, methodType);
} else if (constant instanceof DynamicConstant) {
DynamicConstant.Resolved dynamicConstant = pool.resolvedDynamicConstantAt(getDeclaringKlass(), cpi);
dynamicConstant.putResolved(frame, top, this);
} else {
CompilerDirectives.transferToInterpreter();
throw EspressoError.unimplemented(constant.toString());
}
}
use of com.oracle.truffle.espresso.classfile.RuntimeConstantPool in project graal by oracle.
the class BytecodeNode method quickenInvokeDynamic.
private int quickenInvokeDynamic(final VirtualFrame frame, int top, int curBCI, int opcode) {
CompilerDirectives.transferToInterpreterAndInvalidate();
assert (Bytecodes.INVOKEDYNAMIC == opcode);
RuntimeConstantPool pool = getConstantPool();
BaseQuickNode quick = null;
int indyIndex = -1;
synchronized (this) {
if (bs.currentVolatileBC(curBCI) == QUICK) {
// Check if someone did the job for us. Defer the call until we are out of the lock.
quick = nodes[readCPI(curBCI)];
} else {
// fetch indy under lock.
indyIndex = readCPI(curBCI);
}
}
if (quick != null) {
// Do invocation outside of the lock.
return quick.execute(frame) - Bytecodes.stackEffectOf(opcode);
}
// Resolution should happen outside of the bytecode patching lock.
InvokeDynamicConstant.CallSiteLink link = pool.linkInvokeDynamic(getMethod().getDeclaringKlass(), indyIndex);
// re-lock to check if someone did the job for us, since this was a heavy operation.
synchronized (this) {
if (bs.currentVolatileBC(curBCI) == QUICK) {
// someone beat us to it, just trust him.
quick = nodes[readCPI(curBCI)];
} else {
quick = injectQuick(curBCI, new InvokeDynamicCallSiteNode(link.getMemberName(), link.getUnboxedAppendix(), link.getParsedSignature(), getMeta(), top, curBCI), QUICK);
}
}
return quick.execute(frame) - Bytecodes.stackEffectOf(opcode);
}
Aggregations