Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/shark/sharkState.cpp
32285 views
/*1* Copyright (c) 1999, 2012, 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#include "precompiled.hpp"26#include "ci/ciType.hpp"27#include "ci/ciTypeFlow.hpp"28#include "memory/allocation.hpp"29#include "shark/sharkBuilder.hpp"30#include "shark/sharkCacheDecache.hpp"31#include "shark/sharkState.hpp"32#include "shark/sharkTopLevelBlock.hpp"33#include "shark/sharkType.hpp"34#include "shark/sharkValue.hpp"3536using namespace llvm;3738void SharkState::initialize(const SharkState *state) {39_locals = NEW_RESOURCE_ARRAY(SharkValue*, max_locals());40_stack = NEW_RESOURCE_ARRAY(SharkValue*, max_stack());4142NOT_PRODUCT(memset(_locals, 23, max_locals() * sizeof(SharkValue *)));43NOT_PRODUCT(memset(_stack, 23, max_stack() * sizeof(SharkValue *)));44_sp = _stack;4546if (state) {47for (int i = 0; i < max_locals(); i++) {48SharkValue *value = state->local(i);49if (value)50value = value->clone();51set_local(i, value);52}5354for (int i = state->stack_depth() - 1; i >= 0; i--) {55SharkValue *value = state->stack(i);56if (value)57value = value->clone();58push(value);59}60}6162set_num_monitors(state ? state->num_monitors() : 0);63}6465bool SharkState::equal_to(SharkState *other) {66if (target() != other->target())67return false;6869if (method() != other->method())70return false;7172if (oop_tmp() != other->oop_tmp())73return false;7475if (max_locals() != other->max_locals())76return false;7778if (stack_depth() != other->stack_depth())79return false;8081if (num_monitors() != other->num_monitors())82return false;8384if (has_safepointed() != other->has_safepointed())85return false;8687// Local variables88for (int i = 0; i < max_locals(); i++) {89SharkValue *value = local(i);90SharkValue *other_value = other->local(i);9192if (value == NULL) {93if (other_value != NULL)94return false;95}96else {97if (other_value == NULL)98return false;99100if (!value->equal_to(other_value))101return false;102}103}104105// Expression stack106for (int i = 0; i < stack_depth(); i++) {107SharkValue *value = stack(i);108SharkValue *other_value = other->stack(i);109110if (value == NULL) {111if (other_value != NULL)112return false;113}114else {115if (other_value == NULL)116return false;117118if (!value->equal_to(other_value))119return false;120}121}122123return true;124}125126void SharkState::merge(SharkState* other,127BasicBlock* other_block,128BasicBlock* this_block) {129// Method130Value *this_method = this->method();131Value *other_method = other->method();132if (this_method != other_method) {133PHINode *phi = builder()->CreatePHI(SharkType::Method_type(), 0, "method");134phi->addIncoming(this_method, this_block);135phi->addIncoming(other_method, other_block);136set_method(phi);137}138139// Temporary oop slot140Value *this_oop_tmp = this->oop_tmp();141Value *other_oop_tmp = other->oop_tmp();142if (this_oop_tmp != other_oop_tmp) {143assert(this_oop_tmp && other_oop_tmp, "can't merge NULL with non-NULL");144PHINode *phi = builder()->CreatePHI(SharkType::oop_type(), 0, "oop_tmp");145phi->addIncoming(this_oop_tmp, this_block);146phi->addIncoming(other_oop_tmp, other_block);147set_oop_tmp(phi);148}149150// Monitors151assert(this->num_monitors() == other->num_monitors(), "should be");152153// Local variables154assert(this->max_locals() == other->max_locals(), "should be");155for (int i = 0; i < max_locals(); i++) {156SharkValue *this_value = this->local(i);157SharkValue *other_value = other->local(i);158assert((this_value == NULL) == (other_value == NULL), "should be");159if (this_value != NULL) {160char name[18];161snprintf(name, sizeof(name), "local_%d_", i);162set_local(i, this_value->merge(163builder(), other_value, other_block, this_block, name));164}165}166167// Expression stack168assert(this->stack_depth() == other->stack_depth(), "should be");169for (int i = 0; i < stack_depth(); i++) {170SharkValue *this_value = this->stack(i);171SharkValue *other_value = other->stack(i);172assert((this_value == NULL) == (other_value == NULL), "should be");173if (this_value != NULL) {174char name[18];175snprintf(name, sizeof(name), "stack_%d_", i);176set_stack(i, this_value->merge(177builder(), other_value, other_block, this_block, name));178}179}180181// Safepointed status182set_has_safepointed(this->has_safepointed() && other->has_safepointed());183}184185void SharkState::replace_all(SharkValue* old_value, SharkValue* new_value) {186// Local variables187for (int i = 0; i < max_locals(); i++) {188if (local(i) == old_value)189set_local(i, new_value);190}191192// Expression stack193for (int i = 0; i < stack_depth(); i++) {194if (stack(i) == old_value)195set_stack(i, new_value);196}197}198199SharkNormalEntryState::SharkNormalEntryState(SharkTopLevelBlock* block,200Value* method)201: SharkState(block) {202assert(!block->stack_depth_at_entry(), "entry block shouldn't have stack");203204// Local variables205for (int i = 0; i < max_locals(); i++) {206ciType *type = block->local_type_at_entry(i);207208SharkValue *value = NULL;209switch (type->basic_type()) {210case T_INT:211case T_LONG:212case T_FLOAT:213case T_DOUBLE:214case T_OBJECT:215case T_ARRAY:216if (i >= arg_size()) {217ShouldNotReachHere();218}219value = SharkValue::create_generic(type, NULL, i == 0 && !is_static());220break;221222case ciTypeFlow::StateVector::T_NULL:223value = SharkValue::null();224break;225226case ciTypeFlow::StateVector::T_BOTTOM:227break;228229case ciTypeFlow::StateVector::T_LONG2:230case ciTypeFlow::StateVector::T_DOUBLE2:231break;232233default:234ShouldNotReachHere();235}236set_local(i, value);237}238SharkNormalEntryCacher(block->function(), method).scan(this);239}240241SharkOSREntryState::SharkOSREntryState(SharkTopLevelBlock* block,242Value* method,243Value* osr_buf)244: SharkState(block) {245assert(block->stack_depth_at_entry() == 0, "entry block shouldn't have stack");246set_num_monitors(block->ciblock()->monitor_count());247248// Local variables249for (int i = 0; i < max_locals(); i++) {250ciType *type = block->local_type_at_entry(i);251252SharkValue *value = NULL;253switch (type->basic_type()) {254case T_INT:255case T_LONG:256case T_FLOAT:257case T_DOUBLE:258case T_OBJECT:259case T_ARRAY:260value = SharkValue::create_generic(type, NULL, false);261break;262263case ciTypeFlow::StateVector::T_NULL:264value = SharkValue::null();265break;266267case ciTypeFlow::StateVector::T_BOTTOM:268break;269270case ciTypeFlow::StateVector::T_LONG2:271case ciTypeFlow::StateVector::T_DOUBLE2:272break;273274default:275ShouldNotReachHere();276}277set_local(i, value);278}279SharkOSREntryCacher(block->function(), method, osr_buf).scan(this);280}281282SharkPHIState::SharkPHIState(SharkTopLevelBlock* block)283: SharkState(block), _block(block) {284BasicBlock *saved_insert_point = builder()->GetInsertBlock();285builder()->SetInsertPoint(block->entry_block());286char name[18];287288// Method289set_method(builder()->CreatePHI(SharkType::Method_type(), 0, "method"));290291// Local variables292for (int i = 0; i < max_locals(); i++) {293ciType *type = block->local_type_at_entry(i);294if (type->basic_type() == (BasicType) ciTypeFlow::StateVector::T_NULL) {295// XXX we could do all kinds of clever stuff here296type = ciType::make(T_OBJECT); // XXX what about T_ARRAY?297}298299SharkValue *value = NULL;300switch (type->basic_type()) {301case T_INT:302case T_LONG:303case T_FLOAT:304case T_DOUBLE:305case T_OBJECT:306case T_ARRAY:307snprintf(name, sizeof(name), "local_%d_", i);308value = SharkValue::create_phi(309type, builder()->CreatePHI(SharkType::to_stackType(type), 0, name));310break;311312case T_ADDRESS:313value = SharkValue::address_constant(type->as_return_address()->bci());314break;315316case ciTypeFlow::StateVector::T_BOTTOM:317break;318319case ciTypeFlow::StateVector::T_LONG2:320case ciTypeFlow::StateVector::T_DOUBLE2:321break;322323default:324ShouldNotReachHere();325}326set_local(i, value);327}328329// Expression stack330for (int i = 0; i < block->stack_depth_at_entry(); i++) {331ciType *type = block->stack_type_at_entry(i);332if (type->basic_type() == (BasicType) ciTypeFlow::StateVector::T_NULL) {333// XXX we could do all kinds of clever stuff here334type = ciType::make(T_OBJECT); // XXX what about T_ARRAY?335}336337SharkValue *value = NULL;338switch (type->basic_type()) {339case T_INT:340case T_LONG:341case T_FLOAT:342case T_DOUBLE:343case T_OBJECT:344case T_ARRAY:345snprintf(name, sizeof(name), "stack_%d_", i);346value = SharkValue::create_phi(347type, builder()->CreatePHI(SharkType::to_stackType(type), 0, name));348break;349350case T_ADDRESS:351value = SharkValue::address_constant(type->as_return_address()->bci());352break;353354case ciTypeFlow::StateVector::T_LONG2:355case ciTypeFlow::StateVector::T_DOUBLE2:356break;357358default:359ShouldNotReachHere();360}361push(value);362}363364// Monitors365set_num_monitors(block->ciblock()->monitor_count());366367builder()->SetInsertPoint(saved_insert_point);368}369370void SharkPHIState::add_incoming(SharkState* incoming_state) {371BasicBlock *predecessor = builder()->GetInsertBlock();372373// Method374((PHINode *) method())->addIncoming(incoming_state->method(), predecessor);375376// Local variables377for (int i = 0; i < max_locals(); i++) {378if (local(i) != NULL)379local(i)->addIncoming(incoming_state->local(i), predecessor);380}381382// Expression stack383int stack_depth = block()->stack_depth_at_entry();384assert(stack_depth == incoming_state->stack_depth(), "should be");385for (int i = 0; i < stack_depth; i++) {386assert((stack(i) == NULL) == (incoming_state->stack(i) == NULL), "oops");387if (stack(i))388stack(i)->addIncoming(incoming_state->stack(i), predecessor);389}390391// Monitors392assert(num_monitors() == incoming_state->num_monitors(), "should be");393394// Temporary oop slot395assert(oop_tmp() == incoming_state->oop_tmp(), "should be");396}397398399