Path: blob/master/src/hotspot/cpu/zero/stack_zero.hpp
40931 views
/*1* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.2* Copyright 2008, 2009, 2010 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 CPU_ZERO_STACK_ZERO_HPP26#define CPU_ZERO_STACK_ZERO_HPP2728#include "utilities/align.hpp"29#include "utilities/sizes.hpp"3031class ZeroStack {32private:33intptr_t *_base; // the last available word34intptr_t *_top; // the word past the end of the stack35intptr_t *_sp; // the top word on the stack3637private:38int _shadow_pages_size; // how much ABI stack must we keep free?3940public:41ZeroStack();4243bool needs_setup() const {44return _base == NULL;45}4647int suggest_size(Thread *thread) const;4849void setup(void *mem, size_t size) {50assert(needs_setup(), "already set up");51assert(!(size & WordAlignmentMask), "unaligned");5253_base = (intptr_t *) mem;54_top = _base + (size >> LogBytesPerWord);55_sp = _top;56}57void teardown() {58assert(!needs_setup(), "not set up");59assert(_sp == _top, "stuff on stack at teardown");6061_base = NULL;62_top = NULL;63_sp = NULL;64}6566intptr_t *sp() const {67return _sp;68}69void set_sp(intptr_t *new_sp) {70assert(_top >= new_sp && new_sp >= _base, "bad stack pointer");71_sp = new_sp;72}7374int total_words() const {75return _top - _base;76}77int available_words() const {78return _sp - _base;79}8081void push(intptr_t value) {82assert(_sp > _base, "stack overflow");83*(--_sp) = value;84}85intptr_t pop() {86assert(_sp < _top, "stack underflow");87return *(_sp++);88}8990void *alloc(size_t size) {91int count = align_up(size, wordSize) >> LogBytesPerWord;92assert(count <= available_words(), "stack overflow");93return _sp -= count;94}9596int shadow_pages_size() const {97return _shadow_pages_size;98}99int abi_stack_available(Thread *thread) const;100101public:102void overflow_check(int required_words, TRAPS);103static void handle_overflow(TRAPS);104105public:106void zap(int c) PRODUCT_RETURN;107108public:109static ByteSize base_offset() {110return byte_offset_of(ZeroStack, _base);111}112static ByteSize top_offset() {113return byte_offset_of(ZeroStack, _top);114}115static ByteSize sp_offset() {116return byte_offset_of(ZeroStack, _sp);117}118};119120121class EntryFrame;122class InterpreterFrame;123class FakeStubFrame;124125//126// | ... |127// +--------------------+ ------------------128// | ... | low addresses129// | frame_type |130// | next_frame | high addresses131// +--------------------+ ------------------132// | ... |133134class ZeroFrame {135friend class frame;136friend class ZeroStackPrinter;137138protected:139ZeroFrame() {140ShouldNotCallThis();141}142143enum Layout {144next_frame_off,145frame_type_off,146jf_header_words147};148149enum FrameType {150ENTRY_FRAME = 1,151INTERPRETER_FRAME,152FAKE_STUB_FRAME153};154155protected:156intptr_t *addr_of_word(int offset) const {157return (intptr_t *) this - offset;158}159intptr_t value_of_word(int offset) const {160return *addr_of_word(offset);161}162163public:164ZeroFrame *next() const {165return (ZeroFrame *) value_of_word(next_frame_off);166}167168protected:169FrameType type() const {170return (FrameType) value_of_word(frame_type_off);171}172173public:174bool is_entry_frame() const {175return type() == ENTRY_FRAME;176}177bool is_interpreter_frame() const {178return type() == INTERPRETER_FRAME;179}180bool is_fake_stub_frame() const {181return type() == FAKE_STUB_FRAME;182}183184public:185EntryFrame *as_entry_frame() const {186assert(is_entry_frame(), "should be");187return (EntryFrame *) this;188}189InterpreterFrame *as_interpreter_frame() const {190assert(is_interpreter_frame(), "should be");191return (InterpreterFrame *) this;192}193FakeStubFrame *as_fake_stub_frame() const {194assert(is_fake_stub_frame(), "should be");195return (FakeStubFrame *) this;196}197198public:199void identify_word(int frame_index,200int offset,201char* fieldbuf,202char* valuebuf,203int buflen) const;204205protected:206void identify_vp_word(int frame_index,207intptr_t* addr,208intptr_t* monitor_base,209intptr_t* stack_base,210char* fieldbuf,211int buflen) const;212};213214#endif // CPU_ZERO_STACK_ZERO_HPP215216217