Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/shark/sharkBlock.hpp
32285 views
/*1* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.2* Copyright 2008, 2009 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#ifndef SHARE_VM_SHARK_SHARKBLOCK_HPP26#define SHARE_VM_SHARK_SHARKBLOCK_HPP2728#include "ci/ciMethod.hpp"29#include "ci/ciStreams.hpp"30#include "memory/allocation.hpp"31#include "shark/llvmHeaders.hpp"32#include "shark/sharkBuilder.hpp"33#include "shark/sharkConstant.hpp"34#include "shark/sharkInvariants.hpp"35#include "shark/sharkState.hpp"36#include "shark/sharkValue.hpp"37#include "utilities/debug.hpp"3839class SharkState;4041class SharkBlock : public SharkTargetInvariants {42protected:43SharkBlock(const SharkTargetInvariants* parent)44: SharkTargetInvariants(parent),45_iter(target()),46_current_state(NULL) {}4748SharkBlock(const SharkCompileInvariants* parent, ciMethod* target)49: SharkTargetInvariants(parent, target),50_iter(target),51_current_state(NULL) {}5253private:54ciBytecodeStream _iter;55SharkState* _current_state;5657public:58ciBytecodeStream* iter() {59return &_iter;60}61Bytecodes::Code bc() {62return iter()->cur_bc();63}64int bci() {65return iter()->cur_bci();66}6768// Entry state69protected:70virtual SharkState* entry_state();7172// Current state73private:74SharkState* initial_current_state();7576public:77SharkState* current_state() {78if (_current_state == NULL)79set_current_state(initial_current_state());80return _current_state;81}8283protected:84void set_current_state(SharkState* current_state) {85_current_state = current_state;86}8788// Local variables89protected:90SharkValue* local(int index) {91SharkValue *value = current_state()->local(index);92assert(value != NULL, "shouldn't be");93assert(value->is_one_word() ||94(index + 1 < max_locals() &&95current_state()->local(index + 1) == NULL), "should be");96return value;97}98void set_local(int index, SharkValue* value) {99assert(value != NULL, "shouldn't be");100current_state()->set_local(index, value);101if (value->is_two_word())102current_state()->set_local(index + 1, NULL);103}104105// Expression stack (raw)106protected:107void xpush(SharkValue* value) {108current_state()->push(value);109}110SharkValue* xpop() {111return current_state()->pop();112}113SharkValue* xstack(int slot) {114SharkValue *value = current_state()->stack(slot);115assert(value != NULL, "shouldn't be");116assert(value->is_one_word() ||117(slot > 0 &&118current_state()->stack(slot - 1) == NULL), "should be");119return value;120}121int xstack_depth() {122return current_state()->stack_depth();123}124125// Expression stack (cooked)126protected:127void push(SharkValue* value) {128assert(value != NULL, "shouldn't be");129xpush(value);130if (value->is_two_word())131xpush(NULL);132}133SharkValue* pop() {134int size = current_state()->stack(0) == NULL ? 2 : 1;135if (size == 2)136xpop();137SharkValue *value = xpop();138assert(value && value->size() == size, "should be");139return value;140}141SharkValue* pop_result(BasicType type) {142SharkValue *result = pop();143144#ifdef ASSERT145switch (result->basic_type()) {146case T_BOOLEAN:147case T_BYTE:148case T_CHAR:149case T_SHORT:150assert(type == T_INT, "type mismatch");151break;152153case T_ARRAY:154assert(type == T_OBJECT, "type mismatch");155break;156157default:158assert(result->basic_type() == type, "type mismatch");159}160#endif // ASSERT161162return result;163}164165// Code generation166public:167virtual void emit_IR();168169protected:170void parse_bytecode(int start, int limit);171172// Helpers173protected:174virtual void do_zero_check(SharkValue* value);175176// Zero checking177protected:178void check_null(SharkValue* object) {179zero_check(object);180}181void check_divide_by_zero(SharkValue* value) {182zero_check(value);183}184private:185void zero_check(SharkValue* value) {186if (!value->zero_checked())187do_zero_check(value);188}189190// Safepoints191protected:192virtual void maybe_add_backedge_safepoint();193194// Traps195protected:196virtual bool has_trap();197virtual int trap_request();198virtual int trap_bci();199virtual void do_trap(int trap_request);200201// arraylength202protected:203virtual void do_arraylength();204205// *aload and *astore206protected:207virtual void do_aload(BasicType basic_type);208virtual void do_astore(BasicType basic_type);209210// *div and *rem211private:212void do_idiv() {213do_div_or_rem(false, false);214}215void do_irem() {216do_div_or_rem(false, true);217}218void do_ldiv() {219do_div_or_rem(true, false);220}221void do_lrem() {222do_div_or_rem(true, true);223}224void do_div_or_rem(bool is_long, bool is_rem);225226// get* and put*227private:228void do_getstatic() {229do_field_access(true, false);230}231void do_getfield() {232do_field_access(true, true);233}234void do_putstatic() {235do_field_access(false, false);236}237void do_putfield() {238do_field_access(false, true);239}240void do_field_access(bool is_get, bool is_field);241242// lcmp and [fd]cmp[lg]243private:244void do_lcmp();245void do_fcmp(bool is_double, bool unordered_is_greater);246247// *return and athrow248protected:249virtual void do_return(BasicType type);250virtual void do_athrow();251252// goto*253protected:254virtual void do_goto();255256// jsr* and ret257protected:258virtual void do_jsr();259virtual void do_ret();260261// if*262protected:263virtual void do_if(llvm::ICmpInst::Predicate p, SharkValue* b, SharkValue* a);264265// *switch266protected:267int switch_default_dest();268int switch_table_length();269int switch_key(int i);270int switch_dest(int i);271272virtual void do_switch();273274// invoke*275protected:276virtual void do_call();277278// checkcast and instanceof279protected:280virtual void do_instance_check();281virtual bool maybe_do_instanceof_if();282283// new and *newarray284protected:285virtual void do_new();286virtual void do_newarray();287virtual void do_anewarray();288virtual void do_multianewarray();289290// monitorenter and monitorexit291protected:292virtual void do_monitorenter();293virtual void do_monitorexit();294};295296#endif // SHARE_VM_SHARK_SHARKBLOCK_HPP297298299