Path: blob/master/src/hotspot/share/prims/jvmtiDeferredUpdates.hpp
41144 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_PRIMS_JVMTIDEFERREDUPDATES_HPP26#define SHARE_PRIMS_JVMTIDEFERREDUPDATES_HPP2728#include "runtime/thread.inline.hpp"29#include "utilities/globalDefinitions.hpp"30#include "utilities/growableArray.hpp"3132class jvmtiDeferredLocalVariable : public CHeapObj<mtCompiler> {3334private:3536BasicType _type;37jvalue _value;38int _index;3940public:4142jvmtiDeferredLocalVariable(int index, BasicType type, jvalue value);4344BasicType type(void) { return _type; }45int index(void) { return _index; }46jvalue value(void) { return _value; }4748// Only mutator is for value as only it can change49void set_value(jvalue value) { _value = value; }5051// For gc52oop* oop_addr(void) { return (oop*) &_value.l; }53};5455// In order to implement set_locals for compiled vframes we must56// store updated locals in a data structure that contains enough57// information to recognize equality with a vframe and to store58// any updated locals.5960class StackValueCollection;6162class jvmtiDeferredLocalVariableSet : public CHeapObj<mtCompiler> {63friend class compiledVFrame;6465private:6667Method* _method;68int _bci;69intptr_t* _id;70int _vframe_id;71GrowableArray<jvmtiDeferredLocalVariable*>* _locals;72bool _objects_are_deoptimized;7374void update_value(StackValueCollection* locals, BasicType type, int index, jvalue value);7576void set_value_at(int idx, BasicType typ, jvalue val);7778public:79// JVM state80Method* method() const { return _method; }81int bci() const { return _bci; }82intptr_t* id() const { return _id; }83int vframe_id() const { return _vframe_id; }84bool objects_are_deoptimized() const { return _objects_are_deoptimized; }8586void update_locals(StackValueCollection* locals);87void update_stack(StackValueCollection* locals);88void update_monitors(GrowableArray<MonitorInfo*>* monitors);89void set_objs_are_deoptimized() { _objects_are_deoptimized = true; }9091// Does the vframe match this jvmtiDeferredLocalVariableSet92bool matches(const vframe* vf);9394// Does the underlying physical frame match this jvmtiDeferredLocalVariableSet95bool matches(intptr_t* fr_id) { return id() == fr_id; }9697// GC98void oops_do(OopClosure* f);99100// constructor101jvmtiDeferredLocalVariableSet(Method* method, int bci, intptr_t* id, int vframe_id);102103// destructor104~jvmtiDeferredLocalVariableSet();105};106107// Holds updates for compiled frames by JVMTI agents that cannot be performed immediately.108109class JvmtiDeferredUpdates : public CHeapObj<mtCompiler> {110111// Relocking has to be deferred if the lock owning thread is currently waiting on the monitor.112int _relock_count_after_wait;113114// Deferred updates of locals, expressions, and monitors115GrowableArray<jvmtiDeferredLocalVariableSet*> _deferred_locals_updates;116117void inc_relock_count_after_wait() {118_relock_count_after_wait++;119}120121int get_and_reset_relock_count_after_wait() {122int result = _relock_count_after_wait;123_relock_count_after_wait = 0;124return result;125}126127GrowableArray<jvmtiDeferredLocalVariableSet*>* deferred_locals() { return &_deferred_locals_updates; }128129JvmtiDeferredUpdates() :130_relock_count_after_wait(0),131_deferred_locals_updates((ResourceObj::set_allocation_type((address) &_deferred_locals_updates,132ResourceObj::C_HEAP), 1), mtCompiler) { }133134public:135~JvmtiDeferredUpdates();136137static void create_for(JavaThread* thread);138139static GrowableArray<jvmtiDeferredLocalVariableSet*>* deferred_locals(JavaThread* jt) {140return jt->deferred_updates() == NULL ? NULL : jt->deferred_updates()->deferred_locals();141}142143// Relocking has to be deferred if the lock owning thread is currently waiting on the monitor.144static int get_and_reset_relock_count_after_wait(JavaThread* jt);145static void inc_relock_count_after_wait(JavaThread* thread);146147// Delete deferred updates for the compiled frame with id 'frame_id' on the148// given thread's stack. The thread's JvmtiDeferredUpdates instance will be149// deleted too if no updates remain.150static void delete_updates_for_frame(JavaThread* jt, intptr_t* frame_id);151152// Number of deferred updates153int count() const {154return _deferred_locals_updates.length() + (_relock_count_after_wait > 0 ? 1 : 0);155}156};157158#endif // SHARE_PRIMS_JVMTIDEFERREDUPDATES_HPP159160161