Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/shark/sharkBlock.cpp
32285 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* Copyright 2008, 2009, 2010 Red Hat, Inc.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "interpreter/bytecodes.hpp"27#include "shark/llvmHeaders.hpp"28#include "shark/llvmValue.hpp"29#include "shark/sharkBlock.hpp"30#include "shark/sharkBuilder.hpp"31#include "shark/sharkConstant.hpp"32#include "shark/sharkState.hpp"33#include "shark/sharkValue.hpp"34#include "shark/shark_globals.hpp"35#include "utilities/debug.hpp"3637using namespace llvm;3839void SharkBlock::parse_bytecode(int start, int limit) {40SharkValue *a, *b, *c, *d;41int i;4243// Ensure the current state is initialized before we emit any code,44// so that any setup code for the state is at the start of the block45current_state();4647// Parse the bytecodes48iter()->reset_to_bci(start);49while (iter()->next_bci() < limit) {50NOT_PRODUCT(a = b = c = d = NULL);51iter()->next();5253if (SharkTraceBytecodes)54tty->print_cr("%4d: %s", bci(), Bytecodes::name(bc()));5556if (has_trap() && trap_bci() == bci()) {57do_trap(trap_request());58return;59}6061if (UseLoopSafepoints) {62// XXX if a lcmp is followed by an if_?? then C2 maybe-inserts63// the safepoint before the lcmp rather than before the if.64// Maybe we should do this too. See parse2.cpp for details.65switch (bc()) {66case Bytecodes::_goto:67case Bytecodes::_ifnull:68case Bytecodes::_ifnonnull:69case Bytecodes::_if_acmpeq:70case Bytecodes::_if_acmpne:71case Bytecodes::_ifeq:72case Bytecodes::_ifne:73case Bytecodes::_iflt:74case Bytecodes::_ifle:75case Bytecodes::_ifgt:76case Bytecodes::_ifge:77case Bytecodes::_if_icmpeq:78case Bytecodes::_if_icmpne:79case Bytecodes::_if_icmplt:80case Bytecodes::_if_icmple:81case Bytecodes::_if_icmpgt:82case Bytecodes::_if_icmpge:83if (iter()->get_dest() <= bci())84maybe_add_backedge_safepoint();85break;8687case Bytecodes::_goto_w:88if (iter()->get_far_dest() <= bci())89maybe_add_backedge_safepoint();90break;9192case Bytecodes::_tableswitch:93case Bytecodes::_lookupswitch:94if (switch_default_dest() <= bci()) {95maybe_add_backedge_safepoint();96break;97}98int len = switch_table_length();99for (int i = 0; i < len; i++) {100if (switch_dest(i) <= bci()) {101maybe_add_backedge_safepoint();102break;103}104}105break;106}107}108109switch (bc()) {110case Bytecodes::_nop:111break;112113case Bytecodes::_aconst_null:114push(SharkValue::null());115break;116117case Bytecodes::_iconst_m1:118push(SharkValue::jint_constant(-1));119break;120case Bytecodes::_iconst_0:121push(SharkValue::jint_constant(0));122break;123case Bytecodes::_iconst_1:124push(SharkValue::jint_constant(1));125break;126case Bytecodes::_iconst_2:127push(SharkValue::jint_constant(2));128break;129case Bytecodes::_iconst_3:130push(SharkValue::jint_constant(3));131break;132case Bytecodes::_iconst_4:133push(SharkValue::jint_constant(4));134break;135case Bytecodes::_iconst_5:136push(SharkValue::jint_constant(5));137break;138139case Bytecodes::_lconst_0:140push(SharkValue::jlong_constant(0));141break;142case Bytecodes::_lconst_1:143push(SharkValue::jlong_constant(1));144break;145146case Bytecodes::_fconst_0:147push(SharkValue::jfloat_constant(0));148break;149case Bytecodes::_fconst_1:150push(SharkValue::jfloat_constant(1));151break;152case Bytecodes::_fconst_2:153push(SharkValue::jfloat_constant(2));154break;155156case Bytecodes::_dconst_0:157push(SharkValue::jdouble_constant(0));158break;159case Bytecodes::_dconst_1:160push(SharkValue::jdouble_constant(1));161break;162163case Bytecodes::_bipush:164push(SharkValue::jint_constant(iter()->get_constant_u1()));165break;166case Bytecodes::_sipush:167push(SharkValue::jint_constant(iter()->get_constant_u2()));168break;169170case Bytecodes::_ldc:171case Bytecodes::_ldc_w:172case Bytecodes::_ldc2_w: {173SharkConstant* constant = SharkConstant::for_ldc(iter());174assert(constant->is_loaded(), "trap should handle unloaded classes");175push(constant->value(builder()));176break;177}178case Bytecodes::_iload_0:179case Bytecodes::_lload_0:180case Bytecodes::_fload_0:181case Bytecodes::_dload_0:182case Bytecodes::_aload_0:183push(local(0));184break;185case Bytecodes::_iload_1:186case Bytecodes::_lload_1:187case Bytecodes::_fload_1:188case Bytecodes::_dload_1:189case Bytecodes::_aload_1:190push(local(1));191break;192case Bytecodes::_iload_2:193case Bytecodes::_lload_2:194case Bytecodes::_fload_2:195case Bytecodes::_dload_2:196case Bytecodes::_aload_2:197push(local(2));198break;199case Bytecodes::_iload_3:200case Bytecodes::_lload_3:201case Bytecodes::_fload_3:202case Bytecodes::_dload_3:203case Bytecodes::_aload_3:204push(local(3));205break;206case Bytecodes::_iload:207case Bytecodes::_lload:208case Bytecodes::_fload:209case Bytecodes::_dload:210case Bytecodes::_aload:211push(local(iter()->get_index()));212break;213214case Bytecodes::_baload:215do_aload(T_BYTE);216break;217case Bytecodes::_caload:218do_aload(T_CHAR);219break;220case Bytecodes::_saload:221do_aload(T_SHORT);222break;223case Bytecodes::_iaload:224do_aload(T_INT);225break;226case Bytecodes::_laload:227do_aload(T_LONG);228break;229case Bytecodes::_faload:230do_aload(T_FLOAT);231break;232case Bytecodes::_daload:233do_aload(T_DOUBLE);234break;235case Bytecodes::_aaload:236do_aload(T_OBJECT);237break;238239case Bytecodes::_istore_0:240case Bytecodes::_lstore_0:241case Bytecodes::_fstore_0:242case Bytecodes::_dstore_0:243case Bytecodes::_astore_0:244set_local(0, pop());245break;246case Bytecodes::_istore_1:247case Bytecodes::_lstore_1:248case Bytecodes::_fstore_1:249case Bytecodes::_dstore_1:250case Bytecodes::_astore_1:251set_local(1, pop());252break;253case Bytecodes::_istore_2:254case Bytecodes::_lstore_2:255case Bytecodes::_fstore_2:256case Bytecodes::_dstore_2:257case Bytecodes::_astore_2:258set_local(2, pop());259break;260case Bytecodes::_istore_3:261case Bytecodes::_lstore_3:262case Bytecodes::_fstore_3:263case Bytecodes::_dstore_3:264case Bytecodes::_astore_3:265set_local(3, pop());266break;267case Bytecodes::_istore:268case Bytecodes::_lstore:269case Bytecodes::_fstore:270case Bytecodes::_dstore:271case Bytecodes::_astore:272set_local(iter()->get_index(), pop());273break;274275case Bytecodes::_bastore:276do_astore(T_BYTE);277break;278case Bytecodes::_castore:279do_astore(T_CHAR);280break;281case Bytecodes::_sastore:282do_astore(T_SHORT);283break;284case Bytecodes::_iastore:285do_astore(T_INT);286break;287case Bytecodes::_lastore:288do_astore(T_LONG);289break;290case Bytecodes::_fastore:291do_astore(T_FLOAT);292break;293case Bytecodes::_dastore:294do_astore(T_DOUBLE);295break;296case Bytecodes::_aastore:297do_astore(T_OBJECT);298break;299300case Bytecodes::_pop:301xpop();302break;303case Bytecodes::_pop2:304xpop();305xpop();306break;307case Bytecodes::_swap:308a = xpop();309b = xpop();310xpush(a);311xpush(b);312break;313case Bytecodes::_dup:314a = xpop();315xpush(a);316xpush(a);317break;318case Bytecodes::_dup_x1:319a = xpop();320b = xpop();321xpush(a);322xpush(b);323xpush(a);324break;325case Bytecodes::_dup_x2:326a = xpop();327b = xpop();328c = xpop();329xpush(a);330xpush(c);331xpush(b);332xpush(a);333break;334case Bytecodes::_dup2:335a = xpop();336b = xpop();337xpush(b);338xpush(a);339xpush(b);340xpush(a);341break;342case Bytecodes::_dup2_x1:343a = xpop();344b = xpop();345c = xpop();346xpush(b);347xpush(a);348xpush(c);349xpush(b);350xpush(a);351break;352case Bytecodes::_dup2_x2:353a = xpop();354b = xpop();355c = xpop();356d = xpop();357xpush(b);358xpush(a);359xpush(d);360xpush(c);361xpush(b);362xpush(a);363break;364365case Bytecodes::_arraylength:366do_arraylength();367break;368369case Bytecodes::_getfield:370do_getfield();371break;372case Bytecodes::_getstatic:373do_getstatic();374break;375case Bytecodes::_putfield:376do_putfield();377break;378case Bytecodes::_putstatic:379do_putstatic();380break;381382case Bytecodes::_iadd:383b = pop();384a = pop();385push(SharkValue::create_jint(386builder()->CreateAdd(a->jint_value(), b->jint_value()), false));387break;388case Bytecodes::_isub:389b = pop();390a = pop();391push(SharkValue::create_jint(392builder()->CreateSub(a->jint_value(), b->jint_value()), false));393break;394case Bytecodes::_imul:395b = pop();396a = pop();397push(SharkValue::create_jint(398builder()->CreateMul(a->jint_value(), b->jint_value()), false));399break;400case Bytecodes::_idiv:401do_idiv();402break;403case Bytecodes::_irem:404do_irem();405break;406case Bytecodes::_ineg:407a = pop();408push(SharkValue::create_jint(409builder()->CreateNeg(a->jint_value()), a->zero_checked()));410break;411case Bytecodes::_ishl:412b = pop();413a = pop();414push(SharkValue::create_jint(415builder()->CreateShl(416a->jint_value(),417builder()->CreateAnd(418b->jint_value(), LLVMValue::jint_constant(0x1f))), false));419break;420case Bytecodes::_ishr:421b = pop();422a = pop();423push(SharkValue::create_jint(424builder()->CreateAShr(425a->jint_value(),426builder()->CreateAnd(427b->jint_value(), LLVMValue::jint_constant(0x1f))), false));428break;429case Bytecodes::_iushr:430b = pop();431a = pop();432push(SharkValue::create_jint(433builder()->CreateLShr(434a->jint_value(),435builder()->CreateAnd(436b->jint_value(), LLVMValue::jint_constant(0x1f))), false));437break;438case Bytecodes::_iand:439b = pop();440a = pop();441push(SharkValue::create_jint(442builder()->CreateAnd(a->jint_value(), b->jint_value()), false));443break;444case Bytecodes::_ior:445b = pop();446a = pop();447push(SharkValue::create_jint(448builder()->CreateOr(a->jint_value(), b->jint_value()),449a->zero_checked() && b->zero_checked()));450break;451case Bytecodes::_ixor:452b = pop();453a = pop();454push(SharkValue::create_jint(455builder()->CreateXor(a->jint_value(), b->jint_value()), false));456break;457458case Bytecodes::_ladd:459b = pop();460a = pop();461push(SharkValue::create_jlong(462builder()->CreateAdd(a->jlong_value(), b->jlong_value()), false));463break;464case Bytecodes::_lsub:465b = pop();466a = pop();467push(SharkValue::create_jlong(468builder()->CreateSub(a->jlong_value(), b->jlong_value()), false));469break;470case Bytecodes::_lmul:471b = pop();472a = pop();473push(SharkValue::create_jlong(474builder()->CreateMul(a->jlong_value(), b->jlong_value()), false));475break;476case Bytecodes::_ldiv:477do_ldiv();478break;479case Bytecodes::_lrem:480do_lrem();481break;482case Bytecodes::_lneg:483a = pop();484push(SharkValue::create_jlong(485builder()->CreateNeg(a->jlong_value()), a->zero_checked()));486break;487case Bytecodes::_lshl:488b = pop();489a = pop();490push(SharkValue::create_jlong(491builder()->CreateShl(492a->jlong_value(),493builder()->CreateIntCast(494builder()->CreateAnd(495b->jint_value(), LLVMValue::jint_constant(0x3f)),496SharkType::jlong_type(), true)), false));497break;498case Bytecodes::_lshr:499b = pop();500a = pop();501push(SharkValue::create_jlong(502builder()->CreateAShr(503a->jlong_value(),504builder()->CreateIntCast(505builder()->CreateAnd(506b->jint_value(), LLVMValue::jint_constant(0x3f)),507SharkType::jlong_type(), true)), false));508break;509case Bytecodes::_lushr:510b = pop();511a = pop();512push(SharkValue::create_jlong(513builder()->CreateLShr(514a->jlong_value(),515builder()->CreateIntCast(516builder()->CreateAnd(517b->jint_value(), LLVMValue::jint_constant(0x3f)),518SharkType::jlong_type(), true)), false));519break;520case Bytecodes::_land:521b = pop();522a = pop();523push(SharkValue::create_jlong(524builder()->CreateAnd(a->jlong_value(), b->jlong_value()), false));525break;526case Bytecodes::_lor:527b = pop();528a = pop();529push(SharkValue::create_jlong(530builder()->CreateOr(a->jlong_value(), b->jlong_value()),531a->zero_checked() && b->zero_checked()));532break;533case Bytecodes::_lxor:534b = pop();535a = pop();536push(SharkValue::create_jlong(537builder()->CreateXor(a->jlong_value(), b->jlong_value()), false));538break;539540case Bytecodes::_fadd:541b = pop();542a = pop();543push(SharkValue::create_jfloat(544builder()->CreateFAdd(a->jfloat_value(), b->jfloat_value())));545break;546case Bytecodes::_fsub:547b = pop();548a = pop();549push(SharkValue::create_jfloat(550builder()->CreateFSub(a->jfloat_value(), b->jfloat_value())));551break;552case Bytecodes::_fmul:553b = pop();554a = pop();555push(SharkValue::create_jfloat(556builder()->CreateFMul(a->jfloat_value(), b->jfloat_value())));557break;558case Bytecodes::_fdiv:559b = pop();560a = pop();561push(SharkValue::create_jfloat(562builder()->CreateFDiv(a->jfloat_value(), b->jfloat_value())));563break;564case Bytecodes::_frem:565b = pop();566a = pop();567push(SharkValue::create_jfloat(568builder()->CreateFRem(a->jfloat_value(), b->jfloat_value())));569break;570case Bytecodes::_fneg:571a = pop();572push(SharkValue::create_jfloat(573builder()->CreateFNeg(a->jfloat_value())));574break;575576case Bytecodes::_dadd:577b = pop();578a = pop();579push(SharkValue::create_jdouble(580builder()->CreateFAdd(a->jdouble_value(), b->jdouble_value())));581break;582case Bytecodes::_dsub:583b = pop();584a = pop();585push(SharkValue::create_jdouble(586builder()->CreateFSub(a->jdouble_value(), b->jdouble_value())));587break;588case Bytecodes::_dmul:589b = pop();590a = pop();591push(SharkValue::create_jdouble(592builder()->CreateFMul(a->jdouble_value(), b->jdouble_value())));593break;594case Bytecodes::_ddiv:595b = pop();596a = pop();597push(SharkValue::create_jdouble(598builder()->CreateFDiv(a->jdouble_value(), b->jdouble_value())));599break;600case Bytecodes::_drem:601b = pop();602a = pop();603push(SharkValue::create_jdouble(604builder()->CreateFRem(a->jdouble_value(), b->jdouble_value())));605break;606case Bytecodes::_dneg:607a = pop();608push(SharkValue::create_jdouble(609builder()->CreateFNeg(a->jdouble_value())));610break;611612case Bytecodes::_iinc:613i = iter()->get_index();614set_local(615i,616SharkValue::create_jint(617builder()->CreateAdd(618LLVMValue::jint_constant(iter()->get_iinc_con()),619local(i)->jint_value()), false));620break;621622case Bytecodes::_lcmp:623do_lcmp();624break;625626case Bytecodes::_fcmpl:627do_fcmp(false, false);628break;629case Bytecodes::_fcmpg:630do_fcmp(false, true);631break;632case Bytecodes::_dcmpl:633do_fcmp(true, false);634break;635case Bytecodes::_dcmpg:636do_fcmp(true, true);637break;638639case Bytecodes::_i2l:640a = pop();641push(SharkValue::create_jlong(642builder()->CreateIntCast(643a->jint_value(), SharkType::jlong_type(), true), a->zero_checked()));644break;645case Bytecodes::_i2f:646push(SharkValue::create_jfloat(647builder()->CreateSIToFP(648pop()->jint_value(), SharkType::jfloat_type())));649break;650case Bytecodes::_i2d:651push(SharkValue::create_jdouble(652builder()->CreateSIToFP(653pop()->jint_value(), SharkType::jdouble_type())));654break;655656case Bytecodes::_l2i:657push(SharkValue::create_jint(658builder()->CreateIntCast(659pop()->jlong_value(), SharkType::jint_type(), true), false));660break;661case Bytecodes::_l2f:662push(SharkValue::create_jfloat(663builder()->CreateSIToFP(664pop()->jlong_value(), SharkType::jfloat_type())));665break;666case Bytecodes::_l2d:667push(SharkValue::create_jdouble(668builder()->CreateSIToFP(669pop()->jlong_value(), SharkType::jdouble_type())));670break;671672case Bytecodes::_f2i:673push(SharkValue::create_jint(674builder()->CreateCall(675builder()->f2i(), pop()->jfloat_value()), false));676break;677case Bytecodes::_f2l:678push(SharkValue::create_jlong(679builder()->CreateCall(680builder()->f2l(), pop()->jfloat_value()), false));681break;682case Bytecodes::_f2d:683push(SharkValue::create_jdouble(684builder()->CreateFPExt(685pop()->jfloat_value(), SharkType::jdouble_type())));686break;687688case Bytecodes::_d2i:689push(SharkValue::create_jint(690builder()->CreateCall(691builder()->d2i(), pop()->jdouble_value()), false));692break;693case Bytecodes::_d2l:694push(SharkValue::create_jlong(695builder()->CreateCall(696builder()->d2l(), pop()->jdouble_value()), false));697break;698case Bytecodes::_d2f:699push(SharkValue::create_jfloat(700builder()->CreateFPTrunc(701pop()->jdouble_value(), SharkType::jfloat_type())));702break;703704case Bytecodes::_i2b:705push(SharkValue::create_jint(706builder()->CreateAShr(707builder()->CreateShl(708pop()->jint_value(),709LLVMValue::jint_constant(24)),710LLVMValue::jint_constant(24)), false));711break;712case Bytecodes::_i2c:713push(SharkValue::create_jint(714builder()->CreateAnd(715pop()->jint_value(),716LLVMValue::jint_constant(0xffff)), false));717break;718case Bytecodes::_i2s:719push(SharkValue::create_jint(720builder()->CreateAShr(721builder()->CreateShl(722pop()->jint_value(),723LLVMValue::jint_constant(16)),724LLVMValue::jint_constant(16)), false));725break;726727case Bytecodes::_return:728do_return(T_VOID);729break;730case Bytecodes::_ireturn:731do_return(T_INT);732break;733case Bytecodes::_lreturn:734do_return(T_LONG);735break;736case Bytecodes::_freturn:737do_return(T_FLOAT);738break;739case Bytecodes::_dreturn:740do_return(T_DOUBLE);741break;742case Bytecodes::_areturn:743do_return(T_OBJECT);744break;745746case Bytecodes::_athrow:747do_athrow();748break;749750case Bytecodes::_goto:751case Bytecodes::_goto_w:752do_goto();753break;754755case Bytecodes::_jsr:756case Bytecodes::_jsr_w:757do_jsr();758break;759760case Bytecodes::_ret:761do_ret();762break;763764case Bytecodes::_ifnull:765do_if(ICmpInst::ICMP_EQ, SharkValue::null(), pop());766break;767case Bytecodes::_ifnonnull:768do_if(ICmpInst::ICMP_NE, SharkValue::null(), pop());769break;770case Bytecodes::_if_acmpeq:771b = pop();772a = pop();773do_if(ICmpInst::ICMP_EQ, b, a);774break;775case Bytecodes::_if_acmpne:776b = pop();777a = pop();778do_if(ICmpInst::ICMP_NE, b, a);779break;780case Bytecodes::_ifeq:781do_if(ICmpInst::ICMP_EQ, SharkValue::jint_constant(0), pop());782break;783case Bytecodes::_ifne:784do_if(ICmpInst::ICMP_NE, SharkValue::jint_constant(0), pop());785break;786case Bytecodes::_iflt:787do_if(ICmpInst::ICMP_SLT, SharkValue::jint_constant(0), pop());788break;789case Bytecodes::_ifle:790do_if(ICmpInst::ICMP_SLE, SharkValue::jint_constant(0), pop());791break;792case Bytecodes::_ifgt:793do_if(ICmpInst::ICMP_SGT, SharkValue::jint_constant(0), pop());794break;795case Bytecodes::_ifge:796do_if(ICmpInst::ICMP_SGE, SharkValue::jint_constant(0), pop());797break;798case Bytecodes::_if_icmpeq:799b = pop();800a = pop();801do_if(ICmpInst::ICMP_EQ, b, a);802break;803case Bytecodes::_if_icmpne:804b = pop();805a = pop();806do_if(ICmpInst::ICMP_NE, b, a);807break;808case Bytecodes::_if_icmplt:809b = pop();810a = pop();811do_if(ICmpInst::ICMP_SLT, b, a);812break;813case Bytecodes::_if_icmple:814b = pop();815a = pop();816do_if(ICmpInst::ICMP_SLE, b, a);817break;818case Bytecodes::_if_icmpgt:819b = pop();820a = pop();821do_if(ICmpInst::ICMP_SGT, b, a);822break;823case Bytecodes::_if_icmpge:824b = pop();825a = pop();826do_if(ICmpInst::ICMP_SGE, b, a);827break;828829case Bytecodes::_tableswitch:830case Bytecodes::_lookupswitch:831do_switch();832break;833834case Bytecodes::_invokestatic:835case Bytecodes::_invokespecial:836case Bytecodes::_invokevirtual:837case Bytecodes::_invokeinterface:838do_call();839break;840841case Bytecodes::_instanceof:842// This is a very common construct:843//844// if (object instanceof Klass) {845// something = (Klass) object;846// ...847// }848//849// which gets compiled to something like this:850//851// 28: aload 9852// 30: instanceof <Class Klass>853// 33: ifeq 52854// 36: aload 9855// 38: checkcast <Class Klass>856//857// Handling both bytecodes at once allows us858// to eliminate the checkcast.859if (iter()->next_bci() < limit &&860(iter()->next_bc() == Bytecodes::_ifeq ||861iter()->next_bc() == Bytecodes::_ifne) &&862(!UseLoopSafepoints ||863iter()->next_get_dest() > iter()->next_bci())) {864if (maybe_do_instanceof_if()) {865iter()->next();866if (SharkTraceBytecodes)867tty->print_cr("%4d: %s", bci(), Bytecodes::name(bc()));868break;869}870}871// fall through872case Bytecodes::_checkcast:873do_instance_check();874break;875876case Bytecodes::_new:877do_new();878break;879case Bytecodes::_newarray:880do_newarray();881break;882case Bytecodes::_anewarray:883do_anewarray();884break;885case Bytecodes::_multianewarray:886do_multianewarray();887break;888889case Bytecodes::_monitorenter:890do_monitorenter();891break;892case Bytecodes::_monitorexit:893do_monitorexit();894break;895896default:897ShouldNotReachHere();898}899}900}901902SharkState* SharkBlock::initial_current_state() {903return entry_state()->copy();904}905906int SharkBlock::switch_default_dest() {907return iter()->get_dest_table(0);908}909910int SharkBlock::switch_table_length() {911switch(bc()) {912case Bytecodes::_tableswitch:913return iter()->get_int_table(2) - iter()->get_int_table(1) + 1;914915case Bytecodes::_lookupswitch:916return iter()->get_int_table(1);917918default:919ShouldNotReachHere();920}921}922923int SharkBlock::switch_key(int i) {924switch(bc()) {925case Bytecodes::_tableswitch:926return iter()->get_int_table(1) + i;927928case Bytecodes::_lookupswitch:929return iter()->get_int_table(2 + 2 * i);930931default:932ShouldNotReachHere();933}934}935936int SharkBlock::switch_dest(int i) {937switch(bc()) {938case Bytecodes::_tableswitch:939return iter()->get_dest_table(i + 3);940941case Bytecodes::_lookupswitch:942return iter()->get_dest_table(2 + 2 * i + 1);943944default:945ShouldNotReachHere();946}947}948949void SharkBlock::do_div_or_rem(bool is_long, bool is_rem) {950SharkValue *sb = pop();951SharkValue *sa = pop();952953check_divide_by_zero(sb);954955Value *a, *b, *p, *q;956if (is_long) {957a = sa->jlong_value();958b = sb->jlong_value();959p = LLVMValue::jlong_constant(0x8000000000000000LL);960q = LLVMValue::jlong_constant(-1);961}962else {963a = sa->jint_value();964b = sb->jint_value();965p = LLVMValue::jint_constant(0x80000000);966q = LLVMValue::jint_constant(-1);967}968969BasicBlock *ip = builder()->GetBlockInsertionPoint();970BasicBlock *special_case = builder()->CreateBlock(ip, "special_case");971BasicBlock *general_case = builder()->CreateBlock(ip, "general_case");972BasicBlock *done = builder()->CreateBlock(ip, "done");973974builder()->CreateCondBr(975builder()->CreateAnd(976builder()->CreateICmpEQ(a, p),977builder()->CreateICmpEQ(b, q)),978special_case, general_case);979980builder()->SetInsertPoint(special_case);981Value *special_result;982if (is_rem) {983if (is_long)984special_result = LLVMValue::jlong_constant(0);985else986special_result = LLVMValue::jint_constant(0);987}988else {989special_result = a;990}991builder()->CreateBr(done);992993builder()->SetInsertPoint(general_case);994Value *general_result;995if (is_rem)996general_result = builder()->CreateSRem(a, b);997else998general_result = builder()->CreateSDiv(a, b);999builder()->CreateBr(done);10001001builder()->SetInsertPoint(done);1002PHINode *result;1003if (is_long)1004result = builder()->CreatePHI(SharkType::jlong_type(), 0, "result");1005else1006result = builder()->CreatePHI(SharkType::jint_type(), 0, "result");1007result->addIncoming(special_result, special_case);1008result->addIncoming(general_result, general_case);10091010if (is_long)1011push(SharkValue::create_jlong(result, false));1012else1013push(SharkValue::create_jint(result, false));1014}10151016void SharkBlock::do_field_access(bool is_get, bool is_field) {1017bool will_link;1018ciField *field = iter()->get_field(will_link);1019assert(will_link, "typeflow responsibility");1020assert(is_field != field->is_static(), "mismatch");10211022// Pop the value off the stack where necessary1023SharkValue *value = NULL;1024if (!is_get)1025value = pop();10261027// Find the object we're accessing, if necessary1028Value *object = NULL;1029if (is_field) {1030SharkValue *value = pop();1031check_null(value);1032object = value->generic_value();1033}1034if (is_get && field->is_constant() && field->is_static()) {1035SharkConstant *constant = SharkConstant::for_field(iter());1036if (constant->is_loaded())1037value = constant->value(builder());1038}1039if (!is_get || value == NULL) {1040if (!is_field) {1041object = builder()->CreateInlineOop(field->holder()->java_mirror());1042}1043BasicType basic_type = field->type()->basic_type();1044Type *stack_type = SharkType::to_stackType(basic_type);1045Type *field_type = SharkType::to_arrayType(basic_type);1046Type *type = field_type;1047if (field->is_volatile()) {1048if (field_type == SharkType::jfloat_type()) {1049type = SharkType::jint_type();1050} else if (field_type == SharkType::jdouble_type()) {1051type = SharkType::jlong_type();1052}1053}1054Value *addr = builder()->CreateAddressOfStructEntry(1055object, in_ByteSize(field->offset_in_bytes()),1056PointerType::getUnqual(type),1057"addr");10581059// Do the access1060if (is_get) {1061Value* field_value;1062if (field->is_volatile()) {1063field_value = builder()->CreateAtomicLoad(addr);1064field_value = builder()->CreateBitCast(field_value, field_type);1065} else {1066field_value = builder()->CreateLoad(addr);1067}1068if (field_type != stack_type) {1069field_value = builder()->CreateIntCast(1070field_value, stack_type, basic_type != T_CHAR);1071}10721073value = SharkValue::create_generic(field->type(), field_value, false);1074}1075else {1076Value *field_value = value->generic_value();10771078if (field_type != stack_type) {1079field_value = builder()->CreateIntCast(1080field_value, field_type, basic_type != T_CHAR);1081}10821083if (field->is_volatile()) {1084field_value = builder()->CreateBitCast(field_value, type);1085builder()->CreateAtomicStore(field_value, addr);1086} else {1087builder()->CreateStore(field_value, addr);1088}10891090if (!field->type()->is_primitive_type()) {1091builder()->CreateUpdateBarrierSet(oopDesc::bs(), addr);1092}1093}1094}10951096// Push the value onto the stack where necessary1097if (is_get)1098push(value);1099}11001101void SharkBlock::do_lcmp() {1102Value *b = pop()->jlong_value();1103Value *a = pop()->jlong_value();11041105BasicBlock *ip = builder()->GetBlockInsertionPoint();1106BasicBlock *ne = builder()->CreateBlock(ip, "lcmp_ne");1107BasicBlock *lt = builder()->CreateBlock(ip, "lcmp_lt");1108BasicBlock *gt = builder()->CreateBlock(ip, "lcmp_gt");1109BasicBlock *done = builder()->CreateBlock(ip, "done");11101111BasicBlock *eq = builder()->GetInsertBlock();1112builder()->CreateCondBr(builder()->CreateICmpEQ(a, b), done, ne);11131114builder()->SetInsertPoint(ne);1115builder()->CreateCondBr(builder()->CreateICmpSLT(a, b), lt, gt);11161117builder()->SetInsertPoint(lt);1118builder()->CreateBr(done);11191120builder()->SetInsertPoint(gt);1121builder()->CreateBr(done);11221123builder()->SetInsertPoint(done);1124PHINode *result = builder()->CreatePHI(SharkType::jint_type(), 0, "result");1125result->addIncoming(LLVMValue::jint_constant(-1), lt);1126result->addIncoming(LLVMValue::jint_constant(0), eq);1127result->addIncoming(LLVMValue::jint_constant(1), gt);11281129push(SharkValue::create_jint(result, false));1130}11311132void SharkBlock::do_fcmp(bool is_double, bool unordered_is_greater) {1133Value *a, *b;1134if (is_double) {1135b = pop()->jdouble_value();1136a = pop()->jdouble_value();1137}1138else {1139b = pop()->jfloat_value();1140a = pop()->jfloat_value();1141}11421143BasicBlock *ip = builder()->GetBlockInsertionPoint();1144BasicBlock *ordered = builder()->CreateBlock(ip, "ordered");1145BasicBlock *ge = builder()->CreateBlock(ip, "fcmp_ge");1146BasicBlock *lt = builder()->CreateBlock(ip, "fcmp_lt");1147BasicBlock *eq = builder()->CreateBlock(ip, "fcmp_eq");1148BasicBlock *gt = builder()->CreateBlock(ip, "fcmp_gt");1149BasicBlock *done = builder()->CreateBlock(ip, "done");11501151builder()->CreateCondBr(1152builder()->CreateFCmpUNO(a, b),1153unordered_is_greater ? gt : lt, ordered);11541155builder()->SetInsertPoint(ordered);1156builder()->CreateCondBr(builder()->CreateFCmpULT(a, b), lt, ge);11571158builder()->SetInsertPoint(ge);1159builder()->CreateCondBr(builder()->CreateFCmpUGT(a, b), gt, eq);11601161builder()->SetInsertPoint(lt);1162builder()->CreateBr(done);11631164builder()->SetInsertPoint(gt);1165builder()->CreateBr(done);11661167builder()->SetInsertPoint(eq);1168builder()->CreateBr(done);11691170builder()->SetInsertPoint(done);1171PHINode *result = builder()->CreatePHI(SharkType::jint_type(), 0, "result");1172result->addIncoming(LLVMValue::jint_constant(-1), lt);1173result->addIncoming(LLVMValue::jint_constant(0), eq);1174result->addIncoming(LLVMValue::jint_constant(1), gt);11751176push(SharkValue::create_jint(result, false));1177}11781179void SharkBlock::emit_IR() {1180ShouldNotCallThis();1181}11821183SharkState* SharkBlock::entry_state() {1184ShouldNotCallThis();1185}11861187void SharkBlock::do_zero_check(SharkValue* value) {1188ShouldNotCallThis();1189}11901191void SharkBlock::maybe_add_backedge_safepoint() {1192ShouldNotCallThis();1193}11941195bool SharkBlock::has_trap() {1196return false;1197}11981199int SharkBlock::trap_request() {1200ShouldNotCallThis();1201}12021203int SharkBlock::trap_bci() {1204ShouldNotCallThis();1205}12061207void SharkBlock::do_trap(int trap_request) {1208ShouldNotCallThis();1209}12101211void SharkBlock::do_arraylength() {1212ShouldNotCallThis();1213}12141215void SharkBlock::do_aload(BasicType basic_type) {1216ShouldNotCallThis();1217}12181219void SharkBlock::do_astore(BasicType basic_type) {1220ShouldNotCallThis();1221}12221223void SharkBlock::do_return(BasicType type) {1224ShouldNotCallThis();1225}12261227void SharkBlock::do_athrow() {1228ShouldNotCallThis();1229}12301231void SharkBlock::do_goto() {1232ShouldNotCallThis();1233}12341235void SharkBlock::do_jsr() {1236ShouldNotCallThis();1237}12381239void SharkBlock::do_ret() {1240ShouldNotCallThis();1241}12421243void SharkBlock::do_if(ICmpInst::Predicate p, SharkValue* b, SharkValue* a) {1244ShouldNotCallThis();1245}12461247void SharkBlock::do_switch() {1248ShouldNotCallThis();1249}12501251void SharkBlock::do_call() {1252ShouldNotCallThis();1253}12541255void SharkBlock::do_instance_check() {1256ShouldNotCallThis();1257}12581259bool SharkBlock::maybe_do_instanceof_if() {1260ShouldNotCallThis();1261}12621263void SharkBlock::do_new() {1264ShouldNotCallThis();1265}12661267void SharkBlock::do_newarray() {1268ShouldNotCallThis();1269}12701271void SharkBlock::do_anewarray() {1272ShouldNotCallThis();1273}12741275void SharkBlock::do_multianewarray() {1276ShouldNotCallThis();1277}12781279void SharkBlock::do_monitorenter() {1280ShouldNotCallThis();1281}12821283void SharkBlock::do_monitorexit() {1284ShouldNotCallThis();1285}128612871288