1612N/A/*
1879N/A * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
1612N/A * Copyright 2008, 2009 Red Hat, Inc.
1612N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1612N/A *
1612N/A * This code is free software; you can redistribute it and/or modify it
1612N/A * under the terms of the GNU General Public License version 2 only, as
1612N/A * published by the Free Software Foundation.
1612N/A *
1612N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1612N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1612N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1612N/A * version 2 for more details (a copy is included in the LICENSE file that
1612N/A * accompanied this code).
1612N/A *
1612N/A * You should have received a copy of the GNU General Public License version
1612N/A * 2 along with this work; if not, write to the Free Software Foundation,
1612N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1612N/A *
1612N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1612N/A * or visit www.oracle.com if you need additional information or have any
1612N/A * questions.
1612N/A *
1612N/A */
1612N/A
1879N/A#ifndef SHARE_VM_SHARK_SHARKBLOCK_HPP
1879N/A#define SHARE_VM_SHARK_SHARKBLOCK_HPP
1879N/A
1879N/A#include "ci/ciMethod.hpp"
1879N/A#include "ci/ciStreams.hpp"
1879N/A#include "memory/allocation.hpp"
1879N/A#include "shark/llvmHeaders.hpp"
1879N/A#include "shark/sharkBuilder.hpp"
1879N/A#include "shark/sharkConstant.hpp"
1879N/A#include "shark/sharkInvariants.hpp"
1879N/A#include "shark/sharkState.hpp"
1879N/A#include "shark/sharkValue.hpp"
1879N/A#include "utilities/debug.hpp"
1879N/A
1612N/Aclass SharkState;
1612N/A
1612N/Aclass SharkBlock : public SharkTargetInvariants {
1612N/A protected:
1612N/A SharkBlock(const SharkTargetInvariants* parent)
1612N/A : SharkTargetInvariants(parent),
1612N/A _iter(target()),
1612N/A _current_state(NULL) {}
1612N/A
1612N/A SharkBlock(const SharkCompileInvariants* parent, ciMethod* target)
1612N/A : SharkTargetInvariants(parent, target),
1612N/A _iter(target),
1612N/A _current_state(NULL) {}
1612N/A
1612N/A private:
1612N/A ciBytecodeStream _iter;
1612N/A SharkState* _current_state;
1612N/A
1612N/A public:
1612N/A ciBytecodeStream* iter() {
1612N/A return &_iter;
1612N/A }
1612N/A Bytecodes::Code bc() {
1612N/A return iter()->cur_bc();
1612N/A }
1612N/A int bci() {
1612N/A return iter()->cur_bci();
1612N/A }
1612N/A
1612N/A // Entry state
1612N/A protected:
1612N/A virtual SharkState* entry_state();
1612N/A
1612N/A // Current state
1612N/A private:
1612N/A SharkState* initial_current_state();
1612N/A
1612N/A public:
1612N/A SharkState* current_state() {
1612N/A if (_current_state == NULL)
1612N/A set_current_state(initial_current_state());
1612N/A return _current_state;
1612N/A }
1612N/A
1612N/A protected:
1612N/A void set_current_state(SharkState* current_state) {
1612N/A _current_state = current_state;
1612N/A }
1612N/A
1612N/A // Local variables
1612N/A protected:
1612N/A SharkValue* local(int index) {
1612N/A SharkValue *value = current_state()->local(index);
1612N/A assert(value != NULL, "shouldn't be");
1612N/A assert(value->is_one_word() ||
1612N/A (index + 1 < max_locals() &&
1612N/A current_state()->local(index + 1) == NULL), "should be");
1612N/A return value;
1612N/A }
1612N/A void set_local(int index, SharkValue* value) {
1612N/A assert(value != NULL, "shouldn't be");
1612N/A current_state()->set_local(index, value);
1612N/A if (value->is_two_word())
1612N/A current_state()->set_local(index + 1, NULL);
1612N/A }
1612N/A
1612N/A // Expression stack (raw)
1612N/A protected:
1612N/A void xpush(SharkValue* value) {
1612N/A current_state()->push(value);
1612N/A }
1612N/A SharkValue* xpop() {
1612N/A return current_state()->pop();
1612N/A }
1612N/A SharkValue* xstack(int slot) {
1612N/A SharkValue *value = current_state()->stack(slot);
1612N/A assert(value != NULL, "shouldn't be");
1612N/A assert(value->is_one_word() ||
1612N/A (slot > 0 &&
1612N/A current_state()->stack(slot - 1) == NULL), "should be");
1612N/A return value;
1612N/A }
1612N/A int xstack_depth() {
1612N/A return current_state()->stack_depth();
1612N/A }
1612N/A
1612N/A // Expression stack (cooked)
1612N/A protected:
1612N/A void push(SharkValue* value) {
1612N/A assert(value != NULL, "shouldn't be");
1612N/A xpush(value);
1612N/A if (value->is_two_word())
1612N/A xpush(NULL);
1612N/A }
1612N/A SharkValue* pop() {
1612N/A int size = current_state()->stack(0) == NULL ? 2 : 1;
1612N/A if (size == 2)
1612N/A xpop();
1612N/A SharkValue *value = xpop();
1612N/A assert(value && value->size() == size, "should be");
1612N/A return value;
1612N/A }
1612N/A SharkValue* pop_result(BasicType type) {
1612N/A SharkValue *result = pop();
1612N/A
1612N/A#ifdef ASSERT
1612N/A switch (result->basic_type()) {
1612N/A case T_BOOLEAN:
1612N/A case T_BYTE:
1612N/A case T_CHAR:
1612N/A case T_SHORT:
1612N/A assert(type == T_INT, "type mismatch");
1612N/A break;
1612N/A
1612N/A case T_ARRAY:
1612N/A assert(type == T_OBJECT, "type mismatch");
1612N/A break;
1612N/A
1612N/A default:
1612N/A assert(result->basic_type() == type, "type mismatch");
1612N/A }
1612N/A#endif // ASSERT
1612N/A
1612N/A return result;
1612N/A }
1612N/A
1612N/A // Code generation
1612N/A public:
1612N/A virtual void emit_IR();
1612N/A
1612N/A protected:
1612N/A void parse_bytecode(int start, int limit);
1612N/A
1612N/A // Helpers
1612N/A protected:
1612N/A virtual void do_zero_check(SharkValue* value);
1612N/A
1612N/A // Zero checking
1612N/A protected:
1612N/A void check_null(SharkValue* object) {
1612N/A zero_check(object);
1612N/A }
1612N/A void check_divide_by_zero(SharkValue* value) {
1612N/A zero_check(value);
1612N/A }
1612N/A private:
1612N/A void zero_check(SharkValue* value) {
1612N/A if (!value->zero_checked())
1612N/A do_zero_check(value);
1612N/A }
1612N/A
1612N/A // Safepoints
1612N/A protected:
1612N/A virtual void maybe_add_backedge_safepoint();
1612N/A
1612N/A // Traps
1612N/A protected:
1612N/A virtual bool has_trap();
1612N/A virtual int trap_request();
1612N/A virtual int trap_bci();
1612N/A virtual void do_trap(int trap_request);
1612N/A
1612N/A // arraylength
1612N/A protected:
1612N/A virtual void do_arraylength();
1612N/A
1612N/A // *aload and *astore
1612N/A protected:
1612N/A virtual void do_aload(BasicType basic_type);
1612N/A virtual void do_astore(BasicType basic_type);
1612N/A
1612N/A // *div and *rem
1612N/A private:
1612N/A void do_idiv() {
1612N/A do_div_or_rem(false, false);
1612N/A }
1612N/A void do_irem() {
1612N/A do_div_or_rem(false, true);
1612N/A }
1612N/A void do_ldiv() {
1612N/A do_div_or_rem(true, false);
1612N/A }
1612N/A void do_lrem() {
1612N/A do_div_or_rem(true, true);
1612N/A }
1612N/A void do_div_or_rem(bool is_long, bool is_rem);
1612N/A
1612N/A // get* and put*
1612N/A private:
1612N/A void do_getstatic() {
1612N/A do_field_access(true, false);
1612N/A }
1612N/A void do_getfield() {
1612N/A do_field_access(true, true);
1612N/A }
1612N/A void do_putstatic() {
1612N/A do_field_access(false, false);
1612N/A }
1612N/A void do_putfield() {
1612N/A do_field_access(false, true);
1612N/A }
1612N/A void do_field_access(bool is_get, bool is_field);
1612N/A
1612N/A // lcmp and [fd]cmp[lg]
1612N/A private:
1612N/A void do_lcmp();
1612N/A void do_fcmp(bool is_double, bool unordered_is_greater);
1612N/A
1612N/A // *return and athrow
1612N/A protected:
1612N/A virtual void do_return(BasicType type);
1612N/A virtual void do_athrow();
1612N/A
1612N/A // goto*
1612N/A protected:
1612N/A virtual void do_goto();
1612N/A
1612N/A // jsr* and ret
1612N/A protected:
1612N/A virtual void do_jsr();
1612N/A virtual void do_ret();
1612N/A
1612N/A // if*
1612N/A protected:
1612N/A virtual void do_if(llvm::ICmpInst::Predicate p, SharkValue* b, SharkValue* a);
1612N/A
1612N/A // *switch
1612N/A protected:
1612N/A int switch_default_dest();
1612N/A int switch_table_length();
1612N/A int switch_key(int i);
1612N/A int switch_dest(int i);
1612N/A
1612N/A virtual void do_switch();
1612N/A
1612N/A // invoke*
1612N/A protected:
1612N/A virtual void do_call();
1612N/A
1612N/A // checkcast and instanceof
1612N/A protected:
1612N/A virtual void do_instance_check();
1612N/A virtual bool maybe_do_instanceof_if();
1612N/A
1612N/A // new and *newarray
1612N/A protected:
1612N/A virtual void do_new();
1612N/A virtual void do_newarray();
1612N/A virtual void do_anewarray();
1612N/A virtual void do_multianewarray();
1612N/A
1612N/A // monitorenter and monitorexit
1612N/A protected:
1612N/A virtual void do_monitorenter();
1612N/A virtual void do_monitorexit();
1612N/A};
1879N/A
1879N/A#endif // SHARE_VM_SHARK_SHARKBLOCK_HPP