Path: blob/master/src/hotspot/share/runtime/escapeBarrier.hpp
40951 views
/*1* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2020 SAP SE. All rights reserved.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_RUNTIME_ESCAPEBARRIER_HPP26#define SHARE_RUNTIME_ESCAPEBARRIER_HPP2728#include "compiler/compiler_globals.hpp"29#include "memory/allocation.hpp"30#include "utilities/macros.hpp"3132class JavaThread;3334// EscapeBarriers should be put on execution paths where JVMTI agents can access object35// references held by java threads.36// They provide means to revert optimizations based on escape analysis in a well synchronized manner37// just before local references escape through JVMTI.3839class EscapeBarrier : StackObj {4041#if COMPILER2_OR_JVMCI42JavaThread* const _calling_thread;43JavaThread* const _deoptee_thread;44bool const _barrier_active;4546static bool _deoptimizing_objects_for_all_threads;47static bool _self_deoptimization_in_progress;4849// Suspending is necessary because the target thread's stack must be walked and50// object reallocation is not possible in a handshake or at a safepoint.51// Suspending is based on handshakes. It is sufficient if the target thread(s)52// cannot return to executing bytecodes. Acquiring a lock is ok. Leaving a53// safepoint/handshake safe state is not ok.54// See also JavaThread::wait_for_object_deoptimization().55void sync_and_suspend_one();56void sync_and_suspend_all();57void resume_one();58void resume_all();5960// Deoptimize the given frame and deoptimize objects with optimizations based on escape analysis.61bool deoptimize_objects_internal(JavaThread* deoptee, intptr_t* fr_id);6263// Deoptimize objects, i.e. reallocate and relock them. The target frames are deoptimized.64// The methods return false iff at least one reallocation failed.65bool deoptimize_objects(intptr_t* fr_id) {66return deoptimize_objects_internal(deoptee_thread(), fr_id);67}6869public:70// Revert ea based optimizations for given deoptee thread71EscapeBarrier(bool barrier_active, JavaThread* calling_thread, JavaThread* deoptee_thread)72: _calling_thread(calling_thread), _deoptee_thread(deoptee_thread),73_barrier_active(barrier_active && (JVMCI_ONLY(UseJVMCICompiler) NOT_JVMCI(false)74COMPILER2_PRESENT(|| DoEscapeAnalysis)))75{76if (_barrier_active) sync_and_suspend_one();77}7879// Revert ea based optimizations for all java threads80EscapeBarrier(bool barrier_active, JavaThread* calling_thread)81: _calling_thread(calling_thread), _deoptee_thread(NULL),82_barrier_active(barrier_active && (JVMCI_ONLY(UseJVMCICompiler) NOT_JVMCI(false)83COMPILER2_PRESENT(|| DoEscapeAnalysis)))84{85if (_barrier_active) sync_and_suspend_all();86}8788#else8990public:91EscapeBarrier(bool barrier_active, JavaThread* calling_thread, JavaThread* deoptee_thread) { }92EscapeBarrier(bool barrier_active, JavaThread* calling_thread) { }93static bool deoptimizing_objects_for_all_threads() { return false; }94bool barrier_active() const { return false; }95#endif // COMPILER2_OR_JVMCI9697// Deoptimize objects of frames of the target thread up to the given depth.98// Deoptimize objects of caller frames if they passed references to ArgEscape objects as arguments.99// Return false in the case of a reallocation failure and true otherwise.100bool deoptimize_objects(int depth) {101return deoptimize_objects(0, depth);102}103104// Deoptimize objects of frames of the target thread at depth >= d1 and depth <= d2.105// Deoptimize objects of caller frames if they passed references to ArgEscape objects as arguments.106// Return false in the case of a reallocation failure and true otherwise.107bool deoptimize_objects(int d1, int d2) NOT_COMPILER2_OR_JVMCI_RETURN_(true);108109// Find and deoptimize non escaping objects and the holding frames on all stacks.110bool deoptimize_objects_all_threads() NOT_COMPILER2_OR_JVMCI_RETURN_(true);111112// A java thread was added to the list of threads.113static void thread_added(JavaThread* jt) NOT_COMPILER2_OR_JVMCI_RETURN;114115// A java thread was removed from the list of threads.116static void thread_removed(JavaThread* jt) NOT_COMPILER2_OR_JVMCI_RETURN;117118#if COMPILER2_OR_JVMCI119// Returns true iff objects were reallocated and relocked because of access through JVMTI.120static bool objs_are_deoptimized(JavaThread* thread, intptr_t* fr_id);121122static bool deoptimizing_objects_for_all_threads() { return _deoptimizing_objects_for_all_threads; }123124~EscapeBarrier() {125if (!barrier_active()) return;126if (all_threads()) {127resume_all();128} else {129resume_one();130}131}132133// Should revert optimizations for all threads.134bool all_threads() const { return _deoptee_thread == NULL; }135136// Current thread deoptimizes its own objects.137bool self_deopt() const { return _calling_thread == _deoptee_thread; }138139// Inactive barriers are created if no local objects can escape.140bool barrier_active() const { return _barrier_active; }141142// accessors143JavaThread* calling_thread() const { return _calling_thread; }144JavaThread* deoptee_thread() const { return _deoptee_thread; }145#endif // COMPILER2_OR_JVMCI146};147148#endif // SHARE_RUNTIME_ESCAPEBARRIER_HPP149150151