Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/classfile/stackMapFrame.hpp
32285 views
/*1* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_CLASSFILE_STACKMAPFRAME_HPP25#define SHARE_VM_CLASSFILE_STACKMAPFRAME_HPP2627#include "classfile/verificationType.hpp"28#include "classfile/verifier.hpp"29#include "oops/method.hpp"30#include "runtime/handles.hpp"31#include "runtime/signature.hpp"32#include "utilities/exceptions.hpp"3334// A StackMapFrame represents one frame in the stack map attribute.3536class TypeContext;3738enum {39FLAG_THIS_UNINIT = 0x0140};4142class StackMapFrame : public ResourceObj {43private:44int32_t _offset;4546// See comment in StackMapTable about _frame_count about why these47// fields are int32_t instead of u2.48int32_t _locals_size; // number of valid type elements in _locals49int32_t _stack_size; // number of valid type elements in _stack5051int32_t _stack_mark; // Records the size of the stack prior to an52// instruction modification, to allow rewinding53// when/if an error occurs.5455int32_t _max_locals;56int32_t _max_stack;5758u1 _flags;59VerificationType* _locals; // local variable type array60VerificationType* _stack; // operand stack type array6162ClassVerifier* _verifier; // the verifier verifying this method6364StackMapFrame(const StackMapFrame& cp) :65_offset(cp._offset), _locals_size(cp._locals_size),66_stack_size(cp._stack_size), _stack_mark(cp._stack_mark),67_max_locals(cp._max_locals), _max_stack(cp._max_stack),68_flags(cp._flags) {69_locals = NEW_RESOURCE_ARRAY(VerificationType, _max_locals);70for (int i = 0; i < _max_locals; ++i) {71if (i < _locals_size) {72_locals[i] = cp._locals[i];73} else {74_locals[i] = VerificationType::bogus_type();75}76}77int ss = MAX2(_stack_size, _stack_mark);78_stack = NEW_RESOURCE_ARRAY(VerificationType, _max_stack);79for (int i = 0; i < _max_stack; ++i) {80if (i < ss) {81_stack[i] = cp._stack[i];82} else {83_stack[i] = VerificationType::bogus_type();84}85}86_verifier = NULL;87}8889public:90// constructors9192// This constructor is used by the type checker to allocate frames93// in type state, which have _max_locals and _max_stack array elements94// in _locals and _stack.95StackMapFrame(u2 max_locals, u2 max_stack, ClassVerifier* verifier);9697// This constructor is used to initialize stackmap frames in stackmap table,98// which have _locals_size and _stack_size array elements in _locals and _stack.99StackMapFrame(int32_t offset,100u1 flags,101u2 locals_size,102u2 stack_size,103u2 max_locals,104u2 max_stack,105VerificationType* locals,106VerificationType* stack,107ClassVerifier* v) : _offset(offset), _flags(flags),108_locals_size(locals_size),109_stack_size(stack_size),110_stack_mark(-1),111_max_locals(max_locals),112_max_stack(max_stack),113_locals(locals), _stack(stack),114_verifier(v) { }115116static StackMapFrame* copy(StackMapFrame* smf) {117return new StackMapFrame(*smf);118}119120inline void set_offset(int32_t offset) { _offset = offset; }121inline void set_verifier(ClassVerifier* v) { _verifier = v; }122inline void set_flags(u1 flags) { _flags = flags; }123inline void set_locals_size(u2 locals_size) { _locals_size = locals_size; }124inline void set_stack_size(u2 stack_size) { _stack_size = _stack_mark = stack_size; }125inline void clear_stack() { _stack_size = 0; }126inline int32_t offset() const { return _offset; }127inline ClassVerifier* verifier() const { return _verifier; }128inline u1 flags() const { return _flags; }129inline int32_t locals_size() const { return _locals_size; }130inline VerificationType* locals() const { return _locals; }131inline int32_t stack_size() const { return _stack_size; }132inline VerificationType* stack() const { return _stack; }133inline int32_t max_locals() const { return _max_locals; }134inline int32_t max_stack() const { return _max_stack; }135inline bool flag_this_uninit() const { return _flags & FLAG_THIS_UNINIT; }136137// Set locals and stack types to bogus138inline void reset() {139int32_t i;140for (i = 0; i < _max_locals; i++) {141_locals[i] = VerificationType::bogus_type();142}143for (i = 0; i < _max_stack; i++) {144_stack[i] = VerificationType::bogus_type();145}146}147148// Return a StackMapFrame with the same local variable array and empty stack.149// Stack array is allocate with unused one element.150StackMapFrame* frame_in_exception_handler(u1 flags);151152// Set local variable type array based on m's signature.153VerificationType set_locals_from_arg(154const methodHandle m, VerificationType thisKlass, TRAPS);155156// Search local variable type array and stack type array.157// Set every element with type of old_object to new_object.158void initialize_object(159VerificationType old_object, VerificationType new_object);160161// Copy local variable type array in src into this local variable type array.162void copy_locals(const StackMapFrame* src);163164// Copy stack type array in src into this stack type array.165void copy_stack(const StackMapFrame* src);166167// Return true if this stack map frame is assignable to target.168bool is_assignable_to(169const StackMapFrame* target, ErrorContext* ctx, TRAPS) const;170171inline void set_mark() {172#ifdef ASSERT173// Put bogus type to indicate it's no longer valid.174if (_stack_mark != -1) {175for (int i = _stack_mark - 1; i >= _stack_size; --i) {176_stack[i] = VerificationType::bogus_type();177}178}179#endif // def ASSERT180_stack_mark = _stack_size;181}182183// Used when an error occurs and we want to reset the stack to the state184// it was before operands were popped off.185void restore() {186if (_stack_mark != -1) {187_stack_size = _stack_mark;188}189}190191// Push type into stack type array.192inline void push_stack(VerificationType type, TRAPS) {193assert(!type.is_check(), "Must be a real type");194if (_stack_size >= _max_stack) {195verifier()->verify_error(196ErrorContext::stack_overflow(_offset, this),197"Operand stack overflow");198return;199}200_stack[_stack_size++] = type;201}202203inline void push_stack_2(204VerificationType type1, VerificationType type2, TRAPS) {205assert(type1.is_long() || type1.is_double(), "must be long/double");206assert(type2.is_long2() || type2.is_double2(), "must be long/double_2");207if (_stack_size >= _max_stack - 1) {208verifier()->verify_error(209ErrorContext::stack_overflow(_offset, this),210"Operand stack overflow");211return;212}213_stack[_stack_size++] = type1;214_stack[_stack_size++] = type2;215}216217// Pop and return the top type on stack without verifying.218inline VerificationType pop_stack(TRAPS) {219if (_stack_size <= 0) {220verifier()->verify_error(221ErrorContext::stack_underflow(_offset, this),222"Operand stack underflow");223return VerificationType::bogus_type();224}225VerificationType top = _stack[--_stack_size];226return top;227}228229// Pop and return the top type on stack type array after verifying it230// is assignable to type.231inline VerificationType pop_stack(VerificationType type, TRAPS) {232if (_stack_size != 0) {233VerificationType top = _stack[_stack_size - 1];234bool subtype = type.is_assignable_from(235top, verifier(), false, CHECK_(VerificationType::bogus_type()));236if (subtype) {237--_stack_size;238return top;239}240}241return pop_stack_ex(type, THREAD);242}243244inline void pop_stack_2(245VerificationType type1, VerificationType type2, TRAPS) {246assert(type1.is_long2() || type1.is_double2(), "must be long/double");247assert(type2.is_long() || type2.is_double(), "must be long/double_2");248if (_stack_size >= 2) {249VerificationType top1 = _stack[_stack_size - 1];250bool subtype1 = type1.is_assignable_from(top1, verifier(), false, CHECK);251VerificationType top2 = _stack[_stack_size - 2];252bool subtype2 = type2.is_assignable_from(top2, verifier(), false, CHECK);253if (subtype1 && subtype2) {254_stack_size -= 2;255return;256}257}258pop_stack_ex(type1, THREAD);259pop_stack_ex(type2, THREAD);260}261262VerificationType local_at(int index) {263return _locals[index];264}265266VerificationType stack_at(int index) {267return _stack[index];268}269270// Uncommon case that throws exceptions.271VerificationType pop_stack_ex(VerificationType type, TRAPS);272273// Return the type at index in local variable array after verifying274// it is assignable to type.275VerificationType get_local(int32_t index, VerificationType type, TRAPS);276// For long/double.277void get_local_2(278int32_t index, VerificationType type1, VerificationType type2, TRAPS);279280// Set element at index in local variable array to type.281void set_local(int32_t index, VerificationType type, TRAPS);282// For long/double.283void set_local_2(284int32_t index, VerificationType type1, VerificationType type2, TRAPS);285286// Private auxiliary method used only in is_assignable_to(StackMapFrame).287// Returns true if src is assignable to target.288int is_assignable_to(289VerificationType* src, VerificationType* target, int32_t len, TRAPS) const;290291TypeOrigin stack_top_ctx();292293void print_on(outputStream* str) const;294};295296#endif // SHARE_VM_CLASSFILE_STACKMAPFRAME_HPP297298299