in src/hotspot/src/share/vm/shark/sharkBlock.cpp [40:901]
void SharkBlock::parse_bytecode(int start, int limit) {
SharkValue *a, *b, *c, *d;
int i;
// Ensure the current state is initialized before we emit any code,
// so that any setup code for the state is at the start of the block
current_state();
// Parse the bytecodes
iter()->reset_to_bci(start);
while (iter()->next_bci() < limit) {
NOT_PRODUCT(a = b = c = d = NULL);
iter()->next();
if (SharkTraceBytecodes)
tty->print_cr("%4d: %s", bci(), Bytecodes::name(bc()));
if (has_trap() && trap_bci() == bci()) {
do_trap(trap_request());
return;
}
if (UseLoopSafepoints) {
// XXX if a lcmp is followed by an if_?? then C2 maybe-inserts
// the safepoint before the lcmp rather than before the if.
// Maybe we should do this too. See parse2.cpp for details.
switch (bc()) {
case Bytecodes::_goto:
case Bytecodes::_ifnull:
case Bytecodes::_ifnonnull:
case Bytecodes::_if_acmpeq:
case Bytecodes::_if_acmpne:
case Bytecodes::_ifeq:
case Bytecodes::_ifne:
case Bytecodes::_iflt:
case Bytecodes::_ifle:
case Bytecodes::_ifgt:
case Bytecodes::_ifge:
case Bytecodes::_if_icmpeq:
case Bytecodes::_if_icmpne:
case Bytecodes::_if_icmplt:
case Bytecodes::_if_icmple:
case Bytecodes::_if_icmpgt:
case Bytecodes::_if_icmpge:
if (iter()->get_dest() <= bci())
maybe_add_backedge_safepoint();
break;
case Bytecodes::_goto_w:
if (iter()->get_far_dest() <= bci())
maybe_add_backedge_safepoint();
break;
case Bytecodes::_tableswitch:
case Bytecodes::_lookupswitch:
if (switch_default_dest() <= bci()) {
maybe_add_backedge_safepoint();
break;
}
int len = switch_table_length();
for (int i = 0; i < len; i++) {
if (switch_dest(i) <= bci()) {
maybe_add_backedge_safepoint();
break;
}
}
break;
}
}
switch (bc()) {
case Bytecodes::_nop:
break;
case Bytecodes::_aconst_null:
push(SharkValue::null());
break;
case Bytecodes::_iconst_m1:
push(SharkValue::jint_constant(-1));
break;
case Bytecodes::_iconst_0:
push(SharkValue::jint_constant(0));
break;
case Bytecodes::_iconst_1:
push(SharkValue::jint_constant(1));
break;
case Bytecodes::_iconst_2:
push(SharkValue::jint_constant(2));
break;
case Bytecodes::_iconst_3:
push(SharkValue::jint_constant(3));
break;
case Bytecodes::_iconst_4:
push(SharkValue::jint_constant(4));
break;
case Bytecodes::_iconst_5:
push(SharkValue::jint_constant(5));
break;
case Bytecodes::_lconst_0:
push(SharkValue::jlong_constant(0));
break;
case Bytecodes::_lconst_1:
push(SharkValue::jlong_constant(1));
break;
case Bytecodes::_fconst_0:
push(SharkValue::jfloat_constant(0));
break;
case Bytecodes::_fconst_1:
push(SharkValue::jfloat_constant(1));
break;
case Bytecodes::_fconst_2:
push(SharkValue::jfloat_constant(2));
break;
case Bytecodes::_dconst_0:
push(SharkValue::jdouble_constant(0));
break;
case Bytecodes::_dconst_1:
push(SharkValue::jdouble_constant(1));
break;
case Bytecodes::_bipush:
push(SharkValue::jint_constant(iter()->get_constant_u1()));
break;
case Bytecodes::_sipush:
push(SharkValue::jint_constant(iter()->get_constant_u2()));
break;
case Bytecodes::_ldc:
case Bytecodes::_ldc_w:
case Bytecodes::_ldc2_w: {
SharkConstant* constant = SharkConstant::for_ldc(iter());
assert(constant->is_loaded(), "trap should handle unloaded classes");
push(constant->value(builder()));
break;
}
case Bytecodes::_iload_0:
case Bytecodes::_lload_0:
case Bytecodes::_fload_0:
case Bytecodes::_dload_0:
case Bytecodes::_aload_0:
push(local(0));
break;
case Bytecodes::_iload_1:
case Bytecodes::_lload_1:
case Bytecodes::_fload_1:
case Bytecodes::_dload_1:
case Bytecodes::_aload_1:
push(local(1));
break;
case Bytecodes::_iload_2:
case Bytecodes::_lload_2:
case Bytecodes::_fload_2:
case Bytecodes::_dload_2:
case Bytecodes::_aload_2:
push(local(2));
break;
case Bytecodes::_iload_3:
case Bytecodes::_lload_3:
case Bytecodes::_fload_3:
case Bytecodes::_dload_3:
case Bytecodes::_aload_3:
push(local(3));
break;
case Bytecodes::_iload:
case Bytecodes::_lload:
case Bytecodes::_fload:
case Bytecodes::_dload:
case Bytecodes::_aload:
push(local(iter()->get_index()));
break;
case Bytecodes::_baload:
do_aload(T_BYTE);
break;
case Bytecodes::_caload:
do_aload(T_CHAR);
break;
case Bytecodes::_saload:
do_aload(T_SHORT);
break;
case Bytecodes::_iaload:
do_aload(T_INT);
break;
case Bytecodes::_laload:
do_aload(T_LONG);
break;
case Bytecodes::_faload:
do_aload(T_FLOAT);
break;
case Bytecodes::_daload:
do_aload(T_DOUBLE);
break;
case Bytecodes::_aaload:
do_aload(T_OBJECT);
break;
case Bytecodes::_istore_0:
case Bytecodes::_lstore_0:
case Bytecodes::_fstore_0:
case Bytecodes::_dstore_0:
case Bytecodes::_astore_0:
set_local(0, pop());
break;
case Bytecodes::_istore_1:
case Bytecodes::_lstore_1:
case Bytecodes::_fstore_1:
case Bytecodes::_dstore_1:
case Bytecodes::_astore_1:
set_local(1, pop());
break;
case Bytecodes::_istore_2:
case Bytecodes::_lstore_2:
case Bytecodes::_fstore_2:
case Bytecodes::_dstore_2:
case Bytecodes::_astore_2:
set_local(2, pop());
break;
case Bytecodes::_istore_3:
case Bytecodes::_lstore_3:
case Bytecodes::_fstore_3:
case Bytecodes::_dstore_3:
case Bytecodes::_astore_3:
set_local(3, pop());
break;
case Bytecodes::_istore:
case Bytecodes::_lstore:
case Bytecodes::_fstore:
case Bytecodes::_dstore:
case Bytecodes::_astore:
set_local(iter()->get_index(), pop());
break;
case Bytecodes::_bastore:
do_astore(T_BYTE);
break;
case Bytecodes::_castore:
do_astore(T_CHAR);
break;
case Bytecodes::_sastore:
do_astore(T_SHORT);
break;
case Bytecodes::_iastore:
do_astore(T_INT);
break;
case Bytecodes::_lastore:
do_astore(T_LONG);
break;
case Bytecodes::_fastore:
do_astore(T_FLOAT);
break;
case Bytecodes::_dastore:
do_astore(T_DOUBLE);
break;
case Bytecodes::_aastore:
do_astore(T_OBJECT);
break;
case Bytecodes::_pop:
xpop();
break;
case Bytecodes::_pop2:
xpop();
xpop();
break;
case Bytecodes::_swap:
a = xpop();
b = xpop();
xpush(a);
xpush(b);
break;
case Bytecodes::_dup:
a = xpop();
xpush(a);
xpush(a);
break;
case Bytecodes::_dup_x1:
a = xpop();
b = xpop();
xpush(a);
xpush(b);
xpush(a);
break;
case Bytecodes::_dup_x2:
a = xpop();
b = xpop();
c = xpop();
xpush(a);
xpush(c);
xpush(b);
xpush(a);
break;
case Bytecodes::_dup2:
a = xpop();
b = xpop();
xpush(b);
xpush(a);
xpush(b);
xpush(a);
break;
case Bytecodes::_dup2_x1:
a = xpop();
b = xpop();
c = xpop();
xpush(b);
xpush(a);
xpush(c);
xpush(b);
xpush(a);
break;
case Bytecodes::_dup2_x2:
a = xpop();
b = xpop();
c = xpop();
d = xpop();
xpush(b);
xpush(a);
xpush(d);
xpush(c);
xpush(b);
xpush(a);
break;
case Bytecodes::_arraylength:
do_arraylength();
break;
case Bytecodes::_getfield:
do_getfield();
break;
case Bytecodes::_getstatic:
do_getstatic();
break;
case Bytecodes::_putfield:
do_putfield();
break;
case Bytecodes::_putstatic:
do_putstatic();
break;
case Bytecodes::_iadd:
b = pop();
a = pop();
push(SharkValue::create_jint(
builder()->CreateAdd(a->jint_value(), b->jint_value()), false));
break;
case Bytecodes::_isub:
b = pop();
a = pop();
push(SharkValue::create_jint(
builder()->CreateSub(a->jint_value(), b->jint_value()), false));
break;
case Bytecodes::_imul:
b = pop();
a = pop();
push(SharkValue::create_jint(
builder()->CreateMul(a->jint_value(), b->jint_value()), false));
break;
case Bytecodes::_idiv:
do_idiv();
break;
case Bytecodes::_irem:
do_irem();
break;
case Bytecodes::_ineg:
a = pop();
push(SharkValue::create_jint(
builder()->CreateNeg(a->jint_value()), a->zero_checked()));
break;
case Bytecodes::_ishl:
b = pop();
a = pop();
push(SharkValue::create_jint(
builder()->CreateShl(
a->jint_value(),
builder()->CreateAnd(
b->jint_value(), LLVMValue::jint_constant(0x1f))), false));
break;
case Bytecodes::_ishr:
b = pop();
a = pop();
push(SharkValue::create_jint(
builder()->CreateAShr(
a->jint_value(),
builder()->CreateAnd(
b->jint_value(), LLVMValue::jint_constant(0x1f))), false));
break;
case Bytecodes::_iushr:
b = pop();
a = pop();
push(SharkValue::create_jint(
builder()->CreateLShr(
a->jint_value(),
builder()->CreateAnd(
b->jint_value(), LLVMValue::jint_constant(0x1f))), false));
break;
case Bytecodes::_iand:
b = pop();
a = pop();
push(SharkValue::create_jint(
builder()->CreateAnd(a->jint_value(), b->jint_value()), false));
break;
case Bytecodes::_ior:
b = pop();
a = pop();
push(SharkValue::create_jint(
builder()->CreateOr(a->jint_value(), b->jint_value()),
a->zero_checked() && b->zero_checked()));
break;
case Bytecodes::_ixor:
b = pop();
a = pop();
push(SharkValue::create_jint(
builder()->CreateXor(a->jint_value(), b->jint_value()), false));
break;
case Bytecodes::_ladd:
b = pop();
a = pop();
push(SharkValue::create_jlong(
builder()->CreateAdd(a->jlong_value(), b->jlong_value()), false));
break;
case Bytecodes::_lsub:
b = pop();
a = pop();
push(SharkValue::create_jlong(
builder()->CreateSub(a->jlong_value(), b->jlong_value()), false));
break;
case Bytecodes::_lmul:
b = pop();
a = pop();
push(SharkValue::create_jlong(
builder()->CreateMul(a->jlong_value(), b->jlong_value()), false));
break;
case Bytecodes::_ldiv:
do_ldiv();
break;
case Bytecodes::_lrem:
do_lrem();
break;
case Bytecodes::_lneg:
a = pop();
push(SharkValue::create_jlong(
builder()->CreateNeg(a->jlong_value()), a->zero_checked()));
break;
case Bytecodes::_lshl:
b = pop();
a = pop();
push(SharkValue::create_jlong(
builder()->CreateShl(
a->jlong_value(),
builder()->CreateIntCast(
builder()->CreateAnd(
b->jint_value(), LLVMValue::jint_constant(0x3f)),
SharkType::jlong_type(), true)), false));
break;
case Bytecodes::_lshr:
b = pop();
a = pop();
push(SharkValue::create_jlong(
builder()->CreateAShr(
a->jlong_value(),
builder()->CreateIntCast(
builder()->CreateAnd(
b->jint_value(), LLVMValue::jint_constant(0x3f)),
SharkType::jlong_type(), true)), false));
break;
case Bytecodes::_lushr:
b = pop();
a = pop();
push(SharkValue::create_jlong(
builder()->CreateLShr(
a->jlong_value(),
builder()->CreateIntCast(
builder()->CreateAnd(
b->jint_value(), LLVMValue::jint_constant(0x3f)),
SharkType::jlong_type(), true)), false));
break;
case Bytecodes::_land:
b = pop();
a = pop();
push(SharkValue::create_jlong(
builder()->CreateAnd(a->jlong_value(), b->jlong_value()), false));
break;
case Bytecodes::_lor:
b = pop();
a = pop();
push(SharkValue::create_jlong(
builder()->CreateOr(a->jlong_value(), b->jlong_value()),
a->zero_checked() && b->zero_checked()));
break;
case Bytecodes::_lxor:
b = pop();
a = pop();
push(SharkValue::create_jlong(
builder()->CreateXor(a->jlong_value(), b->jlong_value()), false));
break;
case Bytecodes::_fadd:
b = pop();
a = pop();
push(SharkValue::create_jfloat(
builder()->CreateFAdd(a->jfloat_value(), b->jfloat_value())));
break;
case Bytecodes::_fsub:
b = pop();
a = pop();
push(SharkValue::create_jfloat(
builder()->CreateFSub(a->jfloat_value(), b->jfloat_value())));
break;
case Bytecodes::_fmul:
b = pop();
a = pop();
push(SharkValue::create_jfloat(
builder()->CreateFMul(a->jfloat_value(), b->jfloat_value())));
break;
case Bytecodes::_fdiv:
b = pop();
a = pop();
push(SharkValue::create_jfloat(
builder()->CreateFDiv(a->jfloat_value(), b->jfloat_value())));
break;
case Bytecodes::_frem:
b = pop();
a = pop();
push(SharkValue::create_jfloat(
builder()->CreateFRem(a->jfloat_value(), b->jfloat_value())));
break;
case Bytecodes::_fneg:
a = pop();
push(SharkValue::create_jfloat(
builder()->CreateFNeg(a->jfloat_value())));
break;
case Bytecodes::_dadd:
b = pop();
a = pop();
push(SharkValue::create_jdouble(
builder()->CreateFAdd(a->jdouble_value(), b->jdouble_value())));
break;
case Bytecodes::_dsub:
b = pop();
a = pop();
push(SharkValue::create_jdouble(
builder()->CreateFSub(a->jdouble_value(), b->jdouble_value())));
break;
case Bytecodes::_dmul:
b = pop();
a = pop();
push(SharkValue::create_jdouble(
builder()->CreateFMul(a->jdouble_value(), b->jdouble_value())));
break;
case Bytecodes::_ddiv:
b = pop();
a = pop();
push(SharkValue::create_jdouble(
builder()->CreateFDiv(a->jdouble_value(), b->jdouble_value())));
break;
case Bytecodes::_drem:
b = pop();
a = pop();
push(SharkValue::create_jdouble(
builder()->CreateFRem(a->jdouble_value(), b->jdouble_value())));
break;
case Bytecodes::_dneg:
a = pop();
push(SharkValue::create_jdouble(
builder()->CreateFNeg(a->jdouble_value())));
break;
case Bytecodes::_iinc:
i = iter()->get_index();
set_local(
i,
SharkValue::create_jint(
builder()->CreateAdd(
LLVMValue::jint_constant(iter()->get_iinc_con()),
local(i)->jint_value()), false));
break;
case Bytecodes::_lcmp:
do_lcmp();
break;
case Bytecodes::_fcmpl:
do_fcmp(false, false);
break;
case Bytecodes::_fcmpg:
do_fcmp(false, true);
break;
case Bytecodes::_dcmpl:
do_fcmp(true, false);
break;
case Bytecodes::_dcmpg:
do_fcmp(true, true);
break;
case Bytecodes::_i2l:
a = pop();
push(SharkValue::create_jlong(
builder()->CreateIntCast(
a->jint_value(), SharkType::jlong_type(), true), a->zero_checked()));
break;
case Bytecodes::_i2f:
push(SharkValue::create_jfloat(
builder()->CreateSIToFP(
pop()->jint_value(), SharkType::jfloat_type())));
break;
case Bytecodes::_i2d:
push(SharkValue::create_jdouble(
builder()->CreateSIToFP(
pop()->jint_value(), SharkType::jdouble_type())));
break;
case Bytecodes::_l2i:
push(SharkValue::create_jint(
builder()->CreateIntCast(
pop()->jlong_value(), SharkType::jint_type(), true), false));
break;
case Bytecodes::_l2f:
push(SharkValue::create_jfloat(
builder()->CreateSIToFP(
pop()->jlong_value(), SharkType::jfloat_type())));
break;
case Bytecodes::_l2d:
push(SharkValue::create_jdouble(
builder()->CreateSIToFP(
pop()->jlong_value(), SharkType::jdouble_type())));
break;
case Bytecodes::_f2i:
push(SharkValue::create_jint(
builder()->CreateCall(
builder()->f2i(), pop()->jfloat_value()), false));
break;
case Bytecodes::_f2l:
push(SharkValue::create_jlong(
builder()->CreateCall(
builder()->f2l(), pop()->jfloat_value()), false));
break;
case Bytecodes::_f2d:
push(SharkValue::create_jdouble(
builder()->CreateFPExt(
pop()->jfloat_value(), SharkType::jdouble_type())));
break;
case Bytecodes::_d2i:
push(SharkValue::create_jint(
builder()->CreateCall(
builder()->d2i(), pop()->jdouble_value()), false));
break;
case Bytecodes::_d2l:
push(SharkValue::create_jlong(
builder()->CreateCall(
builder()->d2l(), pop()->jdouble_value()), false));
break;
case Bytecodes::_d2f:
push(SharkValue::create_jfloat(
builder()->CreateFPTrunc(
pop()->jdouble_value(), SharkType::jfloat_type())));
break;
case Bytecodes::_i2b:
push(SharkValue::create_jint(
builder()->CreateAShr(
builder()->CreateShl(
pop()->jint_value(),
LLVMValue::jint_constant(24)),
LLVMValue::jint_constant(24)), false));
break;
case Bytecodes::_i2c:
push(SharkValue::create_jint(
builder()->CreateAnd(
pop()->jint_value(),
LLVMValue::jint_constant(0xffff)), false));
break;
case Bytecodes::_i2s:
push(SharkValue::create_jint(
builder()->CreateAShr(
builder()->CreateShl(
pop()->jint_value(),
LLVMValue::jint_constant(16)),
LLVMValue::jint_constant(16)), false));
break;
case Bytecodes::_return:
do_return(T_VOID);
break;
case Bytecodes::_ireturn:
do_return(T_INT);
break;
case Bytecodes::_lreturn:
do_return(T_LONG);
break;
case Bytecodes::_freturn:
do_return(T_FLOAT);
break;
case Bytecodes::_dreturn:
do_return(T_DOUBLE);
break;
case Bytecodes::_areturn:
do_return(T_OBJECT);
break;
case Bytecodes::_athrow:
do_athrow();
break;
case Bytecodes::_goto:
case Bytecodes::_goto_w:
do_goto();
break;
case Bytecodes::_jsr:
case Bytecodes::_jsr_w:
do_jsr();
break;
case Bytecodes::_ret:
do_ret();
break;
case Bytecodes::_ifnull:
do_if(ICmpInst::ICMP_EQ, SharkValue::null(), pop());
break;
case Bytecodes::_ifnonnull:
do_if(ICmpInst::ICMP_NE, SharkValue::null(), pop());
break;
case Bytecodes::_if_acmpeq:
b = pop();
a = pop();
do_if(ICmpInst::ICMP_EQ, b, a);
break;
case Bytecodes::_if_acmpne:
b = pop();
a = pop();
do_if(ICmpInst::ICMP_NE, b, a);
break;
case Bytecodes::_ifeq:
do_if(ICmpInst::ICMP_EQ, SharkValue::jint_constant(0), pop());
break;
case Bytecodes::_ifne:
do_if(ICmpInst::ICMP_NE, SharkValue::jint_constant(0), pop());
break;
case Bytecodes::_iflt:
do_if(ICmpInst::ICMP_SLT, SharkValue::jint_constant(0), pop());
break;
case Bytecodes::_ifle:
do_if(ICmpInst::ICMP_SLE, SharkValue::jint_constant(0), pop());
break;
case Bytecodes::_ifgt:
do_if(ICmpInst::ICMP_SGT, SharkValue::jint_constant(0), pop());
break;
case Bytecodes::_ifge:
do_if(ICmpInst::ICMP_SGE, SharkValue::jint_constant(0), pop());
break;
case Bytecodes::_if_icmpeq:
b = pop();
a = pop();
do_if(ICmpInst::ICMP_EQ, b, a);
break;
case Bytecodes::_if_icmpne:
b = pop();
a = pop();
do_if(ICmpInst::ICMP_NE, b, a);
break;
case Bytecodes::_if_icmplt:
b = pop();
a = pop();
do_if(ICmpInst::ICMP_SLT, b, a);
break;
case Bytecodes::_if_icmple:
b = pop();
a = pop();
do_if(ICmpInst::ICMP_SLE, b, a);
break;
case Bytecodes::_if_icmpgt:
b = pop();
a = pop();
do_if(ICmpInst::ICMP_SGT, b, a);
break;
case Bytecodes::_if_icmpge:
b = pop();
a = pop();
do_if(ICmpInst::ICMP_SGE, b, a);
break;
case Bytecodes::_tableswitch:
case Bytecodes::_lookupswitch:
do_switch();
break;
case Bytecodes::_invokestatic:
case Bytecodes::_invokespecial:
case Bytecodes::_invokevirtual:
case Bytecodes::_invokeinterface:
do_call();
break;
case Bytecodes::_instanceof:
// This is a very common construct:
//
// if (object instanceof Klass) {
// something = (Klass) object;
// ...
// }
//
// which gets compiled to something like this:
//
// 28: aload 9
// 30: instanceof <Class Klass>
// 33: ifeq 52
// 36: aload 9
// 38: checkcast <Class Klass>
//
// Handling both bytecodes at once allows us
// to eliminate the checkcast.
if (iter()->next_bci() < limit &&
(iter()->next_bc() == Bytecodes::_ifeq ||
iter()->next_bc() == Bytecodes::_ifne) &&
(!UseLoopSafepoints ||
iter()->next_get_dest() > iter()->next_bci())) {
if (maybe_do_instanceof_if()) {
iter()->next();
if (SharkTraceBytecodes)
tty->print_cr("%4d: %s", bci(), Bytecodes::name(bc()));
break;
}
}
// fall through
case Bytecodes::_checkcast:
do_instance_check();
break;
case Bytecodes::_new:
do_new();
break;
case Bytecodes::_newarray:
do_newarray();
break;
case Bytecodes::_anewarray:
do_anewarray();
break;
case Bytecodes::_multianewarray:
do_multianewarray();
break;
case Bytecodes::_monitorenter:
do_monitorenter();
break;
case Bytecodes::_monitorexit:
do_monitorexit();
break;
default:
ShouldNotReachHere();
}
}
}