use of com.oracle.truffle.espresso.classfile.constantpool.ClassConstant 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.constantpool.ClassConstant in project graal by oracle.
the class MethodVerifier method getTypeFromPool.
private Symbol<Type> getTypeFromPool(int c, String s) {
PoolConstant pc = poolAt(c);
verifyGuarantee(pc.tag() == CLASS, s + pc.toString());
pc.validate(pool);
ClassConstant cc = (ClassConstant) pc;
assert Validation.validClassNameEntry(cc.getName(pool));
Symbol<Type> type = getTypes().fromName(cc.getName(pool));
return type;
}
use of com.oracle.truffle.espresso.classfile.constantpool.ClassConstant in project graal by oracle.
the class BytecodeStream method printBytecode.
public void printBytecode(Klass klass, PrintStream out) {
try {
ConstantPool pool = klass.getConstantPool();
int bci = 0;
int nextBCI = 0;
StringBuilder str = new StringBuilder();
while (nextBCI < endBCI()) {
str.setLength(0);
bci = nextBCI;
int opcode = currentBC(bci);
str.append(bci).append(": ").append(Bytecodes.nameOf(opcode)).append(" ");
nextBCI = nextBCI(bci);
if (Bytecodes.isBranch(opcode)) {
// {bci}: {branch bytecode} {target}
str.append(readBranchDest(bci));
} else if (opcode == Bytecodes.NEW) {
// {bci}: new {class name}
int cpi = readCPI(bci);
ClassConstant cc = (ClassConstant) pool.at(cpi);
str.append(cc.getName(pool));
} else if (opcode == Bytecodes.INVOKEDYNAMIC) {
// {bci}: #{bootstrap method index} -> {name}:{signature}
int cpi = readCPI(bci);
InvokeDynamicConstant idc = (InvokeDynamicConstant) pool.at(cpi);
str.append("#").append(idc.getBootstrapMethodAttrIndex()).append(" -> ").append(idc.getName(pool)).append(":").append(idc.getSignature(pool));
} else if (Bytecodes.isInvoke(opcode)) {
// {bci}: invoke{} {class}.{method name}:{method signature}
int cpi = readCPI(bci);
MethodRefConstant mrc = (MethodRefConstant) pool.at(cpi);
str.append(mrc.getHolderKlassName(pool)).append(".").append(mrc.getName(pool)).append(":").append(mrc.getDescriptor(pool));
} else if (opcode == Bytecodes.TABLESWITCH) {
// @formatter:off
// checkstyle: stop
// {bci}: tableswitch
// {key1}: {target1}
// ...
// {keyN}: {targetN}
// @formatter:on
// Checkstyle: resume
str.append('\n');
BytecodeTableSwitch helper = BytecodeTableSwitch.INSTANCE;
int low = helper.lowKey(this, bci);
int high = helper.highKey(this, bci);
for (int i = low; i != high + 1; i++) {
str.append('\t').append(i).append(": ").append(helper.targetAt(this, bci, i)).append('\n');
}
str.append("\tdefault: ").append(helper.defaultTarget(this, bci));
} else if (opcode == Bytecodes.LOOKUPSWITCH) {
// @formatter:off
// checkstyle: stop
// {bci}: lookupswitch
// {key1}: {target1}
// ...
// {keyN}: {targetN}
// @formatter:on
// Checkstyle: resume
str.append('\n');
BytecodeLookupSwitch helper = BytecodeLookupSwitch.INSTANCE;
int low = 0;
int high = helper.numberOfCases(this, bci) - 1;
for (int i = low; i <= high; i++) {
str.append('\t').append(helper.keyAt(this, bci, i)).append(": ").append(helper.targetAt(this, bci, i));
}
str.append("\tdefault: ").append(helper.defaultTarget(this, bci));
} else if (opcode == Bytecodes.IINC) {
str.append(" ").append(readLocalIndex(bci)).append(" ").append(readIncrement(bci));
} else {
// {bci}: {opcode} {corresponding value}
if (nextBCI - bci == 2) {
str.append(readUByte(bci + 1));
}
if (nextBCI - bci == 3) {
str.append(readShort(bci));
}
if (nextBCI - bci == 5) {
str.append(readInt(bci + 1));
}
}
out.println(str.toString());
}
} catch (Throwable e) {
throw EspressoError.unexpected("Exception thrown during bytecode printing, aborting...", e);
}
}
Aggregations