Path: blob/master/src/hotspot/cpu/zero/stack_zero.cpp
40931 views
/*1* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.2* Copyright 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#include "precompiled.hpp"26#include "interpreter/interpreterRuntime.hpp"27#include "interpreter/zero/bytecodeInterpreter.hpp"28#include "runtime/thread.inline.hpp"29#include "stack_zero.hpp"30#include "stack_zero.inline.hpp"31#include "runtime/frame.inline.hpp"32#include "utilities/align.hpp"3334// Inlined causes circular inclusion with thread.hpp35ZeroStack::ZeroStack()36: _base(NULL), _top(NULL), _sp(NULL) {37_shadow_pages_size = StackOverflow::stack_shadow_zone_size();38}3940int ZeroStack::suggest_size(Thread *thread) const {41assert(needs_setup(), "already set up");42int abi_available = abi_stack_available(thread);43assert(abi_available >= 0, "available abi stack must be >= 0");44return align_down(abi_available / 2, wordSize);45}4647void ZeroStack::handle_overflow(TRAPS) {48JavaThread *thread = THREAD;4950// Set up the frame anchor if it isn't already51bool has_last_Java_frame = thread->has_last_Java_frame();52if (!has_last_Java_frame) {53intptr_t *sp = thread->zero_stack()->sp();54ZeroFrame *frame = thread->top_zero_frame();55while (frame) {56if (frame->is_interpreter_frame()) {57interpreterState istate =58frame->as_interpreter_frame()->interpreter_state();59if (istate->self_link() == istate)60break;61}6263sp = ((intptr_t *) frame) + 1;64frame = frame->next();65}6667if (frame == NULL)68fatal("unrecoverable stack overflow");6970thread->set_last_Java_frame(frame, sp);71}7273// Throw the exception74switch (thread->thread_state()) {75case _thread_in_Java:76InterpreterRuntime::throw_StackOverflowError(thread);77break;7879case _thread_in_vm:80Exceptions::throw_stack_overflow_exception(thread, __FILE__, __LINE__,81methodHandle());82break;8384default:85ShouldNotReachHere();86}8788// Reset the frame anchor if necessary89if (!has_last_Java_frame)90thread->reset_last_Java_frame();91}9293#ifndef PRODUCT94void ZeroStack::zap(int c) {95memset(_base, c, available_words() * wordSize);96}97#endif // PRODUCT9899100