twisti@1818: /* trims@1907: * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved. twisti@1818: * Copyright 2010 Red Hat, Inc. twisti@1818: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. twisti@1818: * twisti@1818: * This code is free software; you can redistribute it and/or modify it twisti@1818: * under the terms of the GNU General Public License version 2 only, as twisti@1818: * published by the Free Software Foundation. twisti@1818: * twisti@1818: * This code is distributed in the hope that it will be useful, but WITHOUT twisti@1818: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or twisti@1818: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License twisti@1818: * version 2 for more details (a copy is included in the LICENSE file that twisti@1818: * accompanied this code). twisti@1818: * twisti@1818: * You should have received a copy of the GNU General Public License version twisti@1818: * 2 along with this work; if not, write to the Free Software Foundation, twisti@1818: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. twisti@1818: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. twisti@1818: * twisti@1818: */ twisti@1818: twisti@1818: #include "incls/_precompiled.incl" twisti@1818: #include "incls/_stack_zero.cpp.incl" twisti@1818: twisti@1866: int ZeroStack::suggest_size(Thread *thread) const { twisti@1866: assert(needs_setup(), "already set up"); twisti@1866: return align_size_down(abi_stack_available(thread) / 2, wordSize); twisti@1866: } twisti@1866: twisti@1818: void ZeroStack::handle_overflow(TRAPS) { twisti@1818: JavaThread *thread = (JavaThread *) THREAD; twisti@1818: twisti@1818: // Set up the frame anchor if it isn't already twisti@1818: bool has_last_Java_frame = thread->has_last_Java_frame(); twisti@1818: if (!has_last_Java_frame) { twisti@1860: intptr_t *sp = thread->zero_stack()->sp(); twisti@1818: ZeroFrame *frame = thread->top_zero_frame(); twisti@1818: while (frame) { twisti@1818: if (frame->is_shark_frame()) twisti@1818: break; twisti@1818: twisti@1818: if (frame->is_interpreter_frame()) { twisti@1818: interpreterState istate = twisti@1818: frame->as_interpreter_frame()->interpreter_state(); twisti@1818: if (istate->self_link() == istate) twisti@1818: break; twisti@1818: } twisti@1818: twisti@1860: sp = ((intptr_t *) frame) + 1; twisti@1818: frame = frame->next(); twisti@1818: } twisti@1818: twisti@1818: if (frame == NULL) twisti@1818: fatal("unrecoverable stack overflow"); twisti@1818: twisti@1860: thread->set_last_Java_frame(frame, sp); twisti@1818: } twisti@1818: twisti@1818: // Throw the exception twisti@1818: switch (thread->thread_state()) { twisti@1818: case _thread_in_Java: twisti@1818: InterpreterRuntime::throw_StackOverflowError(thread); twisti@1818: break; twisti@1818: twisti@1818: case _thread_in_vm: twisti@1818: Exceptions::throw_stack_overflow_exception(thread, __FILE__, __LINE__); twisti@1818: break; twisti@1818: twisti@1818: default: twisti@1818: ShouldNotReachHere(); twisti@1818: } twisti@1818: twisti@1818: // Reset the frame anchor if necessary twisti@1818: if (!has_last_Java_frame) twisti@1818: thread->reset_last_Java_frame(); twisti@1818: } twisti@1860: twisti@1860: #ifndef PRODUCT twisti@1860: void ZeroStack::zap(int c) { twisti@1860: memset(_base, c, available_words() * wordSize); twisti@1860: } twisti@1860: #endif // PRODUCT