Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/shark/sharkValue.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_SHARKVALUE_HPP26#define SHARE_VM_SHARK_SHARKVALUE_HPP2728#include "ci/ciType.hpp"29#include "memory/allocation.hpp"30#include "shark/llvmHeaders.hpp"31#include "shark/llvmValue.hpp"32#include "shark/sharkType.hpp"3334// Items on the stack and in local variables are tracked using35// SharkValue objects.36//37// All SharkValues are one of two core types, SharkNormalValue38// and SharkAddressValue, but no code outside this file should39// ever refer to those directly. The split is because of the40// way JSRs are handled: the typeflow pass expands them into41// multiple copies, so the return addresses pushed by jsr and42// popped by ret only exist at compile time. Having separate43// classes for these allows us to check that our jsr handling44// is correct, via assertions.45//46// There is one more type, SharkPHIValue, which is a subclass47// of SharkNormalValue with a couple of extra methods. Use of48// SharkPHIValue outside of this file is acceptable, so long49// as it is obtained via SharkValue::as_phi().5051class SharkBuilder;52class SharkPHIValue;5354class SharkValue : public ResourceObj {55protected:56SharkValue() {}5758// Cloning59public:60virtual SharkValue* clone() const = 0;6162// Casting63public:64virtual bool is_phi() const;65virtual SharkPHIValue* as_phi();6667// Comparison68public:69virtual bool equal_to(SharkValue* other) const = 0;7071// Type access72public:73virtual BasicType basic_type() const = 0;74virtual ciType* type() const;7576virtual bool is_jint() const;77virtual bool is_jlong() const;78virtual bool is_jfloat() const;79virtual bool is_jdouble() const;80virtual bool is_jobject() const;81virtual bool is_jarray() const;82virtual bool is_address() const;8384virtual int size() const = 0;8586bool is_one_word() const {87return size() == 1;88}89bool is_two_word() const {90return size() == 2;91}9293// Typed conversion from SharkValues94public:95virtual llvm::Value* jint_value() const;96virtual llvm::Value* jlong_value() const;97virtual llvm::Value* jfloat_value() const;98virtual llvm::Value* jdouble_value() const;99virtual llvm::Value* jobject_value() const;100virtual llvm::Value* jarray_value() const;101virtual int address_value() const;102103// Typed conversion to SharkValues104public:105static SharkValue* create_jint(llvm::Value* value, bool zero_checked) {106assert(value->getType() == SharkType::jint_type(), "should be");107return create_generic(ciType::make(T_INT), value, zero_checked);108}109static SharkValue* create_jlong(llvm::Value* value, bool zero_checked) {110assert(value->getType() == SharkType::jlong_type(), "should be");111return create_generic(ciType::make(T_LONG), value, zero_checked);112}113static SharkValue* create_jfloat(llvm::Value* value) {114assert(value->getType() == SharkType::jfloat_type(), "should be");115return create_generic(ciType::make(T_FLOAT), value, false);116}117static SharkValue* create_jdouble(llvm::Value* value) {118assert(value->getType() == SharkType::jdouble_type(), "should be");119return create_generic(ciType::make(T_DOUBLE), value, false);120}121static SharkValue* create_jobject(llvm::Value* value, bool zero_checked) {122assert(value->getType() == SharkType::oop_type(), "should be");123return create_generic(ciType::make(T_OBJECT), value, zero_checked);124}125126// Typed conversion from constants of various types127public:128static SharkValue* jint_constant(jint value) {129return create_jint(LLVMValue::jint_constant(value), value != 0);130}131static SharkValue* jlong_constant(jlong value) {132return create_jlong(LLVMValue::jlong_constant(value), value != 0);133}134static SharkValue* jfloat_constant(jfloat value) {135return create_jfloat(LLVMValue::jfloat_constant(value));136}137static SharkValue* jdouble_constant(jdouble value) {138return create_jdouble(LLVMValue::jdouble_constant(value));139}140static SharkValue* null() {141return create_jobject(LLVMValue::null(), false);142}143static inline SharkValue* address_constant(int bci);144145// Type-losing conversions -- use with care!146public:147virtual llvm::Value* generic_value() const = 0;148virtual llvm::Value* intptr_value(SharkBuilder* builder) const;149150static inline SharkValue* create_generic(ciType* type,151llvm::Value* value,152bool zero_checked);153static inline SharkValue* create_phi(ciType* type,154llvm::PHINode* phi,155const SharkPHIValue* parent = NULL);156157// Phi-style stuff158public:159virtual void addIncoming(SharkValue* value, llvm::BasicBlock* block);160virtual SharkValue* merge(SharkBuilder* builder,161SharkValue* other,162llvm::BasicBlock* other_block,163llvm::BasicBlock* this_block,164const char* name) = 0;165166// Repeated null and divide-by-zero check removal167public:168virtual bool zero_checked() const;169virtual void set_zero_checked(bool zero_checked);170};171172class SharkNormalValue : public SharkValue {173friend class SharkValue;174175protected:176SharkNormalValue(ciType* type, llvm::Value* value, bool zero_checked)177: _type(type), _llvm_value(value), _zero_checked(zero_checked) {}178179private:180ciType* _type;181llvm::Value* _llvm_value;182bool _zero_checked;183184private:185llvm::Value* llvm_value() const {186return _llvm_value;187}188189// Cloning190public:191SharkValue* clone() const;192193// Comparison194public:195bool equal_to(SharkValue* other) const;196197// Type access198public:199ciType* type() const;200BasicType basic_type() const;201int size() const;202203public:204bool is_jint() const;205bool is_jlong() const;206bool is_jfloat() const;207bool is_jdouble() const;208bool is_jobject() const;209bool is_jarray() const;210211// Typed conversions to LLVM values212public:213llvm::Value* jint_value() const;214llvm::Value* jlong_value() const;215llvm::Value* jfloat_value() const;216llvm::Value* jdouble_value() const;217llvm::Value* jobject_value() const;218llvm::Value* jarray_value() const;219220// Type-losing conversions, use with care221public:222llvm::Value* generic_value() const;223llvm::Value* intptr_value(SharkBuilder* builder) const;224225// Phi-style stuff226public:227SharkValue* merge(SharkBuilder* builder,228SharkValue* other,229llvm::BasicBlock* other_block,230llvm::BasicBlock* this_block,231const char* name);232233// Repeated null and divide-by-zero check removal234public:235bool zero_checked() const;236void set_zero_checked(bool zero_checked);237};238239class SharkPHIValue : public SharkNormalValue {240friend class SharkValue;241242protected:243SharkPHIValue(ciType* type, llvm::PHINode* phi, const SharkPHIValue *parent)244: SharkNormalValue(type, phi, parent && parent->zero_checked()),245_parent(parent),246_all_incomers_zero_checked(true) {}247248private:249const SharkPHIValue* _parent;250bool _all_incomers_zero_checked;251252private:253const SharkPHIValue* parent() const {254return _parent;255}256bool is_clone() const {257return parent() != NULL;258}259260public:261bool all_incomers_zero_checked() const {262if (is_clone())263return parent()->all_incomers_zero_checked();264265return _all_incomers_zero_checked;266}267268// Cloning269public:270SharkValue* clone() const;271272// Casting273public:274bool is_phi() const;275SharkPHIValue* as_phi();276277// Phi-style stuff278public:279void addIncoming(SharkValue *value, llvm::BasicBlock* block);280};281282class SharkAddressValue : public SharkValue {283friend class SharkValue;284285protected:286SharkAddressValue(int bci)287: _bci(bci) {}288289private:290int _bci;291292// Cloning293public:294SharkValue* clone() const;295296// Comparison297public:298bool equal_to(SharkValue* other) const;299300// Type access301public:302BasicType basic_type() const;303int size() const;304bool is_address() const;305306// Typed conversion from SharkValues307public:308int address_value() const;309310// Type-losing conversion -- use with care!311public:312llvm::Value* generic_value() const;313314// Phi-style stuff315public:316void addIncoming(SharkValue *value, llvm::BasicBlock* block);317SharkValue* merge(SharkBuilder* builder,318SharkValue* other,319llvm::BasicBlock* other_block,320llvm::BasicBlock* this_block,321const char* name);322};323324// SharkValue methods that can't be declared above325326inline SharkValue* SharkValue::create_generic(ciType* type,327llvm::Value* value,328bool zero_checked) {329return new SharkNormalValue(type, value, zero_checked);330}331332inline SharkValue* SharkValue::create_phi(ciType* type,333llvm::PHINode* phi,334const SharkPHIValue* parent) {335return new SharkPHIValue(type, phi, parent);336}337338inline SharkValue* SharkValue::address_constant(int bci) {339return new SharkAddressValue(bci);340}341342#endif // SHARE_VM_SHARK_SHARKVALUE_HPP343344345