2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2020-02-06 14:29:57 +00:00
|
|
|
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "precompiled.hpp"
|
2019-05-09 14:28:30 +02:00
|
|
|
#include "classfile/symbolTable.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "classfile/systemDictionary.hpp"
|
2019-12-18 11:51:22 -05:00
|
|
|
#include "code/nmethod.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "interpreter/interpreter.hpp"
|
2014-07-10 17:46:35 -07:00
|
|
|
#include "interpreter/oopMapCache.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "jvmtifiles/jvmtiEnv.hpp"
|
2016-04-19 14:14:04 +02:00
|
|
|
#include "logging/log.hpp"
|
|
|
|
#include "logging/logStream.hpp"
|
2018-03-08 09:56:29 +01:00
|
|
|
#include "memory/allocation.inline.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "memory/resourceArea.hpp"
|
|
|
|
#include "oops/instanceKlass.hpp"
|
2015-02-13 14:37:35 +01:00
|
|
|
#include "oops/oop.inline.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "prims/jvmtiAgentThread.hpp"
|
|
|
|
#include "prims/jvmtiEventController.inline.hpp"
|
|
|
|
#include "prims/jvmtiImpl.hpp"
|
|
|
|
#include "prims/jvmtiRedefineClasses.hpp"
|
|
|
|
#include "runtime/deoptimization.hpp"
|
2018-03-21 19:45:24 -04:00
|
|
|
#include "runtime/frame.inline.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "runtime/handles.inline.hpp"
|
2018-03-16 09:12:13 -04:00
|
|
|
#include "runtime/interfaceSupport.inline.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "runtime/javaCalls.hpp"
|
2011-04-28 08:24:46 -07:00
|
|
|
#include "runtime/os.hpp"
|
2011-02-02 14:38:01 -05:00
|
|
|
#include "runtime/serviceThread.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "runtime/signature.hpp"
|
2012-11-27 14:20:21 +01:00
|
|
|
#include "runtime/thread.inline.hpp"
|
2017-11-22 17:54:50 -08:00
|
|
|
#include "runtime/threadSMR.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "runtime/vframe.hpp"
|
|
|
|
#include "runtime/vframe_hp.hpp"
|
2018-12-06 15:44:40 +01:00
|
|
|
#include "runtime/vmOperations.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "utilities/exceptions.hpp"
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// class JvmtiAgentThread
|
|
|
|
//
|
|
|
|
// JavaThread used to wrap a thread started by an agent
|
|
|
|
// using the JVMTI method RunAgentThread.
|
|
|
|
//
|
|
|
|
|
|
|
|
JvmtiAgentThread::JvmtiAgentThread(JvmtiEnv* env, jvmtiStartFunction start_fn, const void *start_arg)
|
|
|
|
: JavaThread(start_function_wrapper) {
|
|
|
|
_env = env;
|
|
|
|
_start_fn = start_fn;
|
|
|
|
_start_arg = start_arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
JvmtiAgentThread::start_function_wrapper(JavaThread *thread, TRAPS) {
|
|
|
|
// It is expected that any Agent threads will be created as
|
|
|
|
// Java Threads. If this is the case, notification of the creation
|
|
|
|
// of the thread is given in JavaThread::thread_main().
|
|
|
|
assert(thread->is_Java_thread(), "debugger thread should be a Java Thread");
|
|
|
|
assert(thread == JavaThread::current(), "sanity check");
|
|
|
|
|
|
|
|
JvmtiAgentThread *dthread = (JvmtiAgentThread *)thread;
|
|
|
|
dthread->call_start_function();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
JvmtiAgentThread::call_start_function() {
|
|
|
|
ThreadToNativeFromVM transition(this);
|
|
|
|
_start_fn(_env->jvmti_external(), jni_environment(), (void*)_start_arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// class GrowableCache - private methods
|
|
|
|
//
|
|
|
|
|
|
|
|
void GrowableCache::recache() {
|
|
|
|
int len = _elements->length();
|
|
|
|
|
2014-12-01 12:16:15 -05:00
|
|
|
FREE_C_HEAP_ARRAY(address, _cache);
|
2012-06-28 17:03:16 -04:00
|
|
|
_cache = NEW_C_HEAP_ARRAY(address,len+1, mtInternal);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
for (int i=0; i<len; i++) {
|
|
|
|
_cache[i] = _elements->at(i)->getCacheValue();
|
|
|
|
//
|
|
|
|
// The cache entry has gone bad. Without a valid frame pointer
|
|
|
|
// value, the entry is useless so we simply delete it in product
|
|
|
|
// mode. The call to remove() will rebuild the cache again
|
|
|
|
// without the bad entry.
|
|
|
|
//
|
|
|
|
if (_cache[i] == NULL) {
|
|
|
|
assert(false, "cannot recache NULL elements");
|
|
|
|
remove(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_cache[len] = NULL;
|
|
|
|
|
|
|
|
_listener_fun(_this_obj,_cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GrowableCache::equals(void* v, GrowableElement *e2) {
|
|
|
|
GrowableElement *e1 = (GrowableElement *) v;
|
|
|
|
assert(e1 != NULL, "e1 != NULL");
|
|
|
|
assert(e2 != NULL, "e2 != NULL");
|
|
|
|
|
|
|
|
return e1->equals(e2);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// class GrowableCache - public methods
|
|
|
|
//
|
|
|
|
|
|
|
|
GrowableCache::GrowableCache() {
|
|
|
|
_this_obj = NULL;
|
|
|
|
_listener_fun = NULL;
|
|
|
|
_elements = NULL;
|
|
|
|
_cache = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GrowableCache::~GrowableCache() {
|
|
|
|
clear();
|
|
|
|
delete _elements;
|
2014-12-01 12:16:15 -05:00
|
|
|
FREE_C_HEAP_ARRAY(address, _cache);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GrowableCache::initialize(void *this_obj, void listener_fun(void *, address*) ) {
|
|
|
|
_this_obj = this_obj;
|
|
|
|
_listener_fun = listener_fun;
|
2020-06-16 09:37:53 +02:00
|
|
|
_elements = new (ResourceObj::C_HEAP, mtServiceability) GrowableArray<GrowableElement*>(5, mtServiceability);
|
2007-12-01 00:00:00 +00:00
|
|
|
recache();
|
|
|
|
}
|
|
|
|
|
|
|
|
// number of elements in the collection
|
|
|
|
int GrowableCache::length() {
|
|
|
|
return _elements->length();
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the value of the index element in the collection
|
|
|
|
GrowableElement* GrowableCache::at(int index) {
|
|
|
|
GrowableElement *e = (GrowableElement *) _elements->at(index);
|
|
|
|
assert(e != NULL, "e != NULL");
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GrowableCache::find(GrowableElement* e) {
|
|
|
|
return _elements->find(e, GrowableCache::equals);
|
|
|
|
}
|
|
|
|
|
|
|
|
// append a copy of the element to the end of the collection
|
|
|
|
void GrowableCache::append(GrowableElement* e) {
|
|
|
|
GrowableElement *new_e = e->clone();
|
|
|
|
_elements->append(new_e);
|
|
|
|
recache();
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove the element at index
|
|
|
|
void GrowableCache::remove (int index) {
|
|
|
|
GrowableElement *e = _elements->at(index);
|
|
|
|
assert(e != NULL, "e != NULL");
|
|
|
|
_elements->remove(e);
|
|
|
|
delete e;
|
|
|
|
recache();
|
|
|
|
}
|
|
|
|
|
|
|
|
// clear out all elements, release all heap space and
|
|
|
|
// let our listener know that things have changed.
|
|
|
|
void GrowableCache::clear() {
|
|
|
|
int len = _elements->length();
|
|
|
|
for (int i=0; i<len; i++) {
|
|
|
|
delete _elements->at(i);
|
|
|
|
}
|
|
|
|
_elements->clear();
|
|
|
|
recache();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// class JvmtiBreakpoint
|
|
|
|
//
|
|
|
|
|
2019-12-19 16:47:59 +01:00
|
|
|
JvmtiBreakpoint::JvmtiBreakpoint(Method* m_method, jlocation location)
|
2020-07-16 08:29:11 -04:00
|
|
|
: _method(m_method), _bci((int)location) {
|
2019-12-19 16:47:59 +01:00
|
|
|
assert(_method != NULL, "No method for breakpoint.");
|
|
|
|
assert(_bci >= 0, "Negative bci for breakpoint.");
|
|
|
|
oop class_holder_oop = _method->method_holder()->klass_holder();
|
2020-08-11 07:29:45 -04:00
|
|
|
_class_holder = OopHandle(JvmtiExport::jvmti_oop_storage(), class_holder_oop);
|
2019-12-19 16:47:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JvmtiBreakpoint::~JvmtiBreakpoint() {
|
2020-07-16 08:29:11 -04:00
|
|
|
if (_class_holder.peek() != NULL) {
|
2020-08-11 07:29:45 -04:00
|
|
|
_class_holder.release(JvmtiExport::jvmti_oop_storage());
|
2019-12-19 16:47:59 +01:00
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void JvmtiBreakpoint::copy(JvmtiBreakpoint& bp) {
|
|
|
|
_method = bp._method;
|
|
|
|
_bci = bp._bci;
|
2020-08-11 07:29:45 -04:00
|
|
|
_class_holder = OopHandle(JvmtiExport::jvmti_oop_storage(), bp._class_holder.resolve());
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool JvmtiBreakpoint::equals(JvmtiBreakpoint& bp) {
|
|
|
|
return _method == bp._method
|
|
|
|
&& _bci == bp._bci;
|
|
|
|
}
|
|
|
|
|
2016-04-26 10:58:03 +02:00
|
|
|
address JvmtiBreakpoint::getBcp() const {
|
2007-12-01 00:00:00 +00:00
|
|
|
return _method->bcp_from(_bci);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JvmtiBreakpoint::each_method_version_do(method_action meth_act) {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
((Method*)_method->*meth_act)(_bci);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2014-09-03 19:13:18 -04:00
|
|
|
// add/remove breakpoint to/from versions of the method that are EMCP.
|
2007-12-01 00:00:00 +00:00
|
|
|
Thread *thread = Thread::current();
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* ik = _method->method_holder();
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* m_name = _method->name();
|
|
|
|
Symbol* m_signature = _method->signature();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2013-09-20 09:30:02 -04:00
|
|
|
// search previous versions if they exist
|
2017-03-15 10:25:37 -04:00
|
|
|
for (InstanceKlass* pv_node = ik->previous_versions();
|
2014-09-03 19:13:18 -04:00
|
|
|
pv_node != NULL;
|
|
|
|
pv_node = pv_node->previous_versions()) {
|
|
|
|
Array<Method*>* methods = pv_node->methods();
|
2013-09-20 09:30:02 -04:00
|
|
|
|
|
|
|
for (int i = methods->length() - 1; i >= 0; i--) {
|
|
|
|
Method* method = methods->at(i);
|
2014-09-03 19:13:18 -04:00
|
|
|
// Only set breakpoints in running EMCP methods.
|
|
|
|
if (method->is_running_emcp() &&
|
2013-09-20 09:30:02 -04:00
|
|
|
method->name() == m_name &&
|
|
|
|
method->signature() == m_signature) {
|
2016-05-09 22:22:15 +02:00
|
|
|
ResourceMark rm;
|
|
|
|
log_debug(redefine, class, breakpoint)
|
|
|
|
("%sing breakpoint in %s(%s)", meth_act == &Method::set_breakpoint ? "sett" : "clear",
|
|
|
|
method->name()->as_C_string(), method->signature()->as_C_string());
|
2013-09-20 09:30:02 -04:00
|
|
|
(method->*meth_act)(_bci);
|
|
|
|
break;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
2013-09-20 09:30:02 -04:00
|
|
|
}
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void JvmtiBreakpoint::set() {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
each_method_version_do(&Method::set_breakpoint);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void JvmtiBreakpoint::clear() {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
each_method_version_do(&Method::clear_breakpoint);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2016-04-26 10:58:03 +02:00
|
|
|
void JvmtiBreakpoint::print_on(outputStream* out) const {
|
2007-12-01 00:00:00 +00:00
|
|
|
#ifndef PRODUCT
|
2016-04-19 14:14:04 +02:00
|
|
|
ResourceMark rm;
|
2007-12-01 00:00:00 +00:00
|
|
|
const char *class_name = (_method == NULL) ? "NULL" : _method->klass_name()->as_C_string();
|
|
|
|
const char *method_name = (_method == NULL) ? "NULL" : _method->name()->as_C_string();
|
2016-04-19 14:14:04 +02:00
|
|
|
out->print("Breakpoint(%s,%s,%d,%p)", class_name, method_name, _bci, getBcp());
|
2007-12-01 00:00:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// class VM_ChangeBreakpoints
|
|
|
|
//
|
|
|
|
// Modify the Breakpoints data structure at a safepoint
|
|
|
|
//
|
|
|
|
|
|
|
|
void VM_ChangeBreakpoints::doit() {
|
|
|
|
switch (_operation) {
|
|
|
|
case SET_BREAKPOINT:
|
|
|
|
_breakpoints->set_at_safepoint(*_bp);
|
|
|
|
break;
|
|
|
|
case CLEAR_BREAKPOINT:
|
|
|
|
_breakpoints->clear_at_safepoint(*_bp);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(false, "Unknown operation");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// class JvmtiBreakpoints
|
|
|
|
//
|
|
|
|
// a JVMTI internal collection of JvmtiBreakpoint
|
|
|
|
//
|
|
|
|
|
|
|
|
JvmtiBreakpoints::JvmtiBreakpoints(void listener_fun(void *,address *)) {
|
|
|
|
_bps.initialize(this,listener_fun);
|
|
|
|
}
|
|
|
|
|
|
|
|
JvmtiBreakpoints:: ~JvmtiBreakpoints() {}
|
|
|
|
|
2016-04-19 14:14:04 +02:00
|
|
|
void JvmtiBreakpoints::print() {
|
2007-12-01 00:00:00 +00:00
|
|
|
#ifndef PRODUCT
|
2016-04-19 14:14:04 +02:00
|
|
|
LogTarget(Trace, jvmti) log;
|
2017-07-21 09:50:12 +02:00
|
|
|
LogStream log_stream(log);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
int n = _bps.length();
|
|
|
|
for (int i=0; i<n; i++) {
|
|
|
|
JvmtiBreakpoint& bp = _bps.at(i);
|
2016-04-19 14:14:04 +02:00
|
|
|
log_stream.print("%d: ", i);
|
2016-04-26 10:58:03 +02:00
|
|
|
bp.print_on(&log_stream);
|
2016-04-19 14:14:04 +02:00
|
|
|
log_stream.cr();
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void JvmtiBreakpoints::set_at_safepoint(JvmtiBreakpoint& bp) {
|
|
|
|
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
|
|
|
|
|
|
|
|
int i = _bps.find(bp);
|
|
|
|
if (i == -1) {
|
|
|
|
_bps.append(bp);
|
|
|
|
bp.set();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void JvmtiBreakpoints::clear_at_safepoint(JvmtiBreakpoint& bp) {
|
|
|
|
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
|
|
|
|
|
|
|
|
int i = _bps.find(bp);
|
|
|
|
if (i != -1) {
|
|
|
|
_bps.remove(i);
|
|
|
|
bp.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int JvmtiBreakpoints::length() { return _bps.length(); }
|
|
|
|
|
|
|
|
int JvmtiBreakpoints::set(JvmtiBreakpoint& bp) {
|
|
|
|
if ( _bps.find(bp) != -1) {
|
|
|
|
return JVMTI_ERROR_DUPLICATE;
|
|
|
|
}
|
2013-06-10 11:30:51 +02:00
|
|
|
VM_ChangeBreakpoints set_breakpoint(VM_ChangeBreakpoints::SET_BREAKPOINT, &bp);
|
2007-12-01 00:00:00 +00:00
|
|
|
VMThread::execute(&set_breakpoint);
|
|
|
|
return JVMTI_ERROR_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int JvmtiBreakpoints::clear(JvmtiBreakpoint& bp) {
|
|
|
|
if ( _bps.find(bp) == -1) {
|
|
|
|
return JVMTI_ERROR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2013-06-10 11:30:51 +02:00
|
|
|
VM_ChangeBreakpoints clear_breakpoint(VM_ChangeBreakpoints::CLEAR_BREAKPOINT, &bp);
|
2007-12-01 00:00:00 +00:00
|
|
|
VMThread::execute(&clear_breakpoint);
|
|
|
|
return JVMTI_ERROR_NONE;
|
|
|
|
}
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
void JvmtiBreakpoints::clearall_in_class_at_safepoint(Klass* klass) {
|
2007-12-01 00:00:00 +00:00
|
|
|
bool changed = true;
|
|
|
|
// We are going to run thru the list of bkpts
|
|
|
|
// and delete some. This deletion probably alters
|
|
|
|
// the list in some implementation defined way such
|
|
|
|
// that when we delete entry i, the next entry might
|
|
|
|
// no longer be at i+1. To be safe, each time we delete
|
|
|
|
// an entry, we'll just start again from the beginning.
|
|
|
|
// We'll stop when we make a pass thru the whole list without
|
|
|
|
// deleting anything.
|
|
|
|
while (changed) {
|
|
|
|
int len = _bps.length();
|
|
|
|
changed = false;
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
JvmtiBreakpoint& bp = _bps.at(i);
|
|
|
|
if (bp.method()->method_holder() == klass) {
|
|
|
|
bp.clear();
|
|
|
|
_bps.remove(i);
|
|
|
|
// This changed 'i' so we have to start over.
|
|
|
|
changed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// class JvmtiCurrentBreakpoints
|
|
|
|
//
|
|
|
|
|
|
|
|
JvmtiBreakpoints *JvmtiCurrentBreakpoints::_jvmti_breakpoints = NULL;
|
|
|
|
address * JvmtiCurrentBreakpoints::_breakpoint_list = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
JvmtiBreakpoints& JvmtiCurrentBreakpoints::get_jvmti_breakpoints() {
|
|
|
|
if (_jvmti_breakpoints != NULL) return (*_jvmti_breakpoints);
|
|
|
|
_jvmti_breakpoints = new JvmtiBreakpoints(listener_fun);
|
|
|
|
assert(_jvmti_breakpoints != NULL, "_jvmti_breakpoints != NULL");
|
|
|
|
return (*_jvmti_breakpoints);
|
|
|
|
}
|
|
|
|
|
|
|
|
void JvmtiCurrentBreakpoints::listener_fun(void *this_obj, address *cache) {
|
|
|
|
JvmtiBreakpoints *this_jvmti = (JvmtiBreakpoints *) this_obj;
|
|
|
|
assert(this_jvmti != NULL, "this_jvmti != NULL");
|
|
|
|
|
|
|
|
debug_only(int n = this_jvmti->length(););
|
|
|
|
assert(cache[n] == NULL, "cache must be NULL terminated");
|
|
|
|
|
|
|
|
set_breakpoint_list(cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// class VM_GetOrSetLocal
|
|
|
|
//
|
|
|
|
|
|
|
|
// Constructor for non-object getter
|
2017-10-31 11:55:09 -04:00
|
|
|
VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type)
|
2007-12-01 00:00:00 +00:00
|
|
|
: _thread(thread)
|
|
|
|
, _calling_thread(NULL)
|
|
|
|
, _depth(depth)
|
|
|
|
, _index(index)
|
|
|
|
, _type(type)
|
|
|
|
, _jvf(NULL)
|
2018-08-08 15:31:07 +02:00
|
|
|
, _set(false)
|
2007-12-01 00:00:00 +00:00
|
|
|
, _result(JVMTI_ERROR_NONE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Constructor for object or non-object setter
|
2017-10-31 11:55:09 -04:00
|
|
|
VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, jint depth, jint index, BasicType type, jvalue value)
|
2007-12-01 00:00:00 +00:00
|
|
|
: _thread(thread)
|
|
|
|
, _calling_thread(NULL)
|
|
|
|
, _depth(depth)
|
|
|
|
, _index(index)
|
|
|
|
, _type(type)
|
|
|
|
, _value(value)
|
|
|
|
, _jvf(NULL)
|
2018-08-08 15:31:07 +02:00
|
|
|
, _set(true)
|
2007-12-01 00:00:00 +00:00
|
|
|
, _result(JVMTI_ERROR_NONE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Constructor for object getter
|
|
|
|
VM_GetOrSetLocal::VM_GetOrSetLocal(JavaThread* thread, JavaThread* calling_thread, jint depth, int index)
|
|
|
|
: _thread(thread)
|
|
|
|
, _calling_thread(calling_thread)
|
|
|
|
, _depth(depth)
|
|
|
|
, _index(index)
|
|
|
|
, _type(T_OBJECT)
|
|
|
|
, _jvf(NULL)
|
2018-08-08 15:31:07 +02:00
|
|
|
, _set(false)
|
2007-12-01 00:00:00 +00:00
|
|
|
, _result(JVMTI_ERROR_NONE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
vframe *VM_GetOrSetLocal::get_vframe() {
|
|
|
|
if (!_thread->has_last_Java_frame()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
RegisterMap reg_map(_thread);
|
|
|
|
vframe *vf = _thread->last_java_vframe(®_map);
|
|
|
|
int d = 0;
|
|
|
|
while ((vf != NULL) && (d < _depth)) {
|
|
|
|
vf = vf->java_sender();
|
|
|
|
d++;
|
|
|
|
}
|
|
|
|
return vf;
|
|
|
|
}
|
|
|
|
|
|
|
|
javaVFrame *VM_GetOrSetLocal::get_java_vframe() {
|
|
|
|
vframe* vf = get_vframe();
|
|
|
|
if (vf == NULL) {
|
|
|
|
_result = JVMTI_ERROR_NO_MORE_FRAMES;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
javaVFrame *jvf = (javaVFrame*)vf;
|
|
|
|
|
2010-12-09 15:04:26 -05:00
|
|
|
if (!vf->is_java_frame()) {
|
2007-12-01 00:00:00 +00:00
|
|
|
_result = JVMTI_ERROR_OPAQUE_FRAME;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return jvf;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the klass is assignable to a type with the given signature.
|
|
|
|
// Another solution could be to use the function Klass::is_subtype_of(type).
|
|
|
|
// But the type class can be forced to load/initialize eagerly in such a case.
|
|
|
|
// This may cause unexpected consequences like CFLH or class-init JVMTI events.
|
|
|
|
// It is better to avoid such a behavior.
|
|
|
|
bool VM_GetOrSetLocal::is_assignable(const char* ty_sign, Klass* klass, Thread* thread) {
|
|
|
|
assert(ty_sign != NULL, "type signature must not be NULL");
|
|
|
|
assert(thread != NULL, "thread must not be NULL");
|
|
|
|
assert(klass != NULL, "klass must not be NULL");
|
|
|
|
|
|
|
|
int len = (int) strlen(ty_sign);
|
2019-10-21 13:13:16 -04:00
|
|
|
if (ty_sign[0] == JVM_SIGNATURE_CLASS &&
|
|
|
|
ty_sign[len-1] == JVM_SIGNATURE_ENDCLASS) { // Need pure class/interface name
|
2007-12-01 00:00:00 +00:00
|
|
|
ty_sign++;
|
|
|
|
len -= 2;
|
|
|
|
}
|
2019-05-14 11:29:18 -04:00
|
|
|
TempNewSymbol ty_sym = SymbolTable::new_symbol(ty_sign, len);
|
2011-01-27 16:11:27 -08:00
|
|
|
if (klass->name() == ty_sym) {
|
2007-12-01 00:00:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Compare primary supers
|
|
|
|
int super_depth = klass->super_depth();
|
|
|
|
int idx;
|
|
|
|
for (idx = 0; idx < super_depth; idx++) {
|
2012-11-12 16:15:05 -05:00
|
|
|
if (klass->primary_super_of_depth(idx)->name() == ty_sym) {
|
2007-12-01 00:00:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Compare secondary supers
|
2018-08-07 15:45:07 -07:00
|
|
|
const Array<Klass*>* sec_supers = klass->secondary_supers();
|
2007-12-01 00:00:00 +00:00
|
|
|
for (idx = 0; idx < sec_supers->length(); idx++) {
|
2012-11-12 16:15:05 -05:00
|
|
|
if (((Klass*) sec_supers->at(idx))->name() == ty_sym) {
|
2007-12-01 00:00:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks error conditions:
|
|
|
|
// JVMTI_ERROR_INVALID_SLOT
|
|
|
|
// JVMTI_ERROR_TYPE_MISMATCH
|
|
|
|
// Returns: 'true' - everything is Ok, 'false' - error code
|
|
|
|
|
2018-11-08 00:07:48 -08:00
|
|
|
bool VM_GetOrSetLocal::check_slot_type_lvt(javaVFrame* jvf) {
|
2020-07-28 07:33:51 -04:00
|
|
|
Method* method = jvf->method();
|
|
|
|
jint num_entries = method->localvariable_table_length();
|
2007-12-01 00:00:00 +00:00
|
|
|
if (num_entries == 0) {
|
|
|
|
_result = JVMTI_ERROR_INVALID_SLOT;
|
|
|
|
return false; // There are no slots
|
|
|
|
}
|
|
|
|
int signature_idx = -1;
|
|
|
|
int vf_bci = jvf->bci();
|
2020-07-28 07:33:51 -04:00
|
|
|
LocalVariableTableElement* table = method->localvariable_table_start();
|
2007-12-01 00:00:00 +00:00
|
|
|
for (int i = 0; i < num_entries; i++) {
|
|
|
|
int start_bci = table[i].start_bci;
|
|
|
|
int end_bci = start_bci + table[i].length;
|
|
|
|
|
|
|
|
// Here we assume that locations of LVT entries
|
|
|
|
// with the same slot number cannot be overlapped
|
|
|
|
if (_index == (jint) table[i].slot && start_bci <= vf_bci && vf_bci <= end_bci) {
|
|
|
|
signature_idx = (int) table[i].descriptor_cp_index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (signature_idx == -1) {
|
|
|
|
_result = JVMTI_ERROR_INVALID_SLOT;
|
|
|
|
return false; // Incorrect slot index
|
|
|
|
}
|
2020-07-28 07:33:51 -04:00
|
|
|
Symbol* sign_sym = method->constants()->symbol_at(signature_idx);
|
2020-02-06 14:29:57 +00:00
|
|
|
BasicType slot_type = Signature::basic_type(sign_sym);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
switch (slot_type) {
|
|
|
|
case T_BYTE:
|
|
|
|
case T_SHORT:
|
|
|
|
case T_CHAR:
|
|
|
|
case T_BOOLEAN:
|
|
|
|
slot_type = T_INT;
|
|
|
|
break;
|
|
|
|
case T_ARRAY:
|
|
|
|
slot_type = T_OBJECT;
|
|
|
|
break;
|
2017-07-06 01:50:26 +02:00
|
|
|
default:
|
|
|
|
break;
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
if (_type != slot_type) {
|
|
|
|
_result = JVMTI_ERROR_TYPE_MISMATCH;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject jobj = _value.l;
|
|
|
|
if (_set && slot_type == T_OBJECT && jobj != NULL) { // NULL reference is allowed
|
|
|
|
// Check that the jobject class matches the return type signature.
|
2020-07-31 09:07:29 +02:00
|
|
|
oop obj = JNIHandles::resolve_external_guard(jobj);
|
2007-12-01 00:00:00 +00:00
|
|
|
NULL_CHECK(obj, (_result = JVMTI_ERROR_INVALID_OBJECT, false));
|
2017-03-15 10:25:37 -04:00
|
|
|
Klass* ob_k = obj->klass();
|
|
|
|
NULL_CHECK(ob_k, (_result = JVMTI_ERROR_INVALID_OBJECT, false));
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2020-02-06 14:29:57 +00:00
|
|
|
const char* signature = (const char *) sign_sym->as_utf8();
|
2020-07-31 09:07:29 +02:00
|
|
|
if (!is_assignable(signature, ob_k, VMThread::vm_thread())) {
|
2007-12-01 00:00:00 +00:00
|
|
|
_result = JVMTI_ERROR_TYPE_MISMATCH;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-08 00:07:48 -08:00
|
|
|
bool VM_GetOrSetLocal::check_slot_type_no_lvt(javaVFrame* jvf) {
|
2020-07-28 07:33:51 -04:00
|
|
|
Method* method = jvf->method();
|
2018-11-08 00:07:48 -08:00
|
|
|
jint extra_slot = (_type == T_LONG || _type == T_DOUBLE) ? 1 : 0;
|
|
|
|
|
2020-07-28 07:33:51 -04:00
|
|
|
if (_index < 0 || _index + extra_slot >= method->max_locals()) {
|
2018-11-08 00:07:48 -08:00
|
|
|
_result = JVMTI_ERROR_INVALID_SLOT;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
StackValueCollection *locals = _jvf->locals();
|
|
|
|
BasicType slot_type = locals->at(_index)->type();
|
|
|
|
|
|
|
|
if (slot_type == T_CONFLICT) {
|
|
|
|
_result = JVMTI_ERROR_INVALID_SLOT;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (extra_slot) {
|
|
|
|
BasicType extra_slot_type = locals->at(_index + 1)->type();
|
|
|
|
if (extra_slot_type != T_INT) {
|
|
|
|
_result = JVMTI_ERROR_INVALID_SLOT;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_type != slot_type && (_type == T_OBJECT || slot_type != T_INT)) {
|
|
|
|
_result = JVMTI_ERROR_TYPE_MISMATCH;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
static bool can_be_deoptimized(vframe* vf) {
|
|
|
|
return (vf->is_compiled_frame() && vf->fr().can_be_deoptimized());
|
|
|
|
}
|
|
|
|
|
2020-07-31 09:07:29 +02:00
|
|
|
void VM_GetOrSetLocal::doit() {
|
2007-12-01 00:00:00 +00:00
|
|
|
_jvf = get_java_vframe();
|
2020-07-31 09:07:29 +02:00
|
|
|
if (_jvf == NULL) {
|
|
|
|
return;
|
|
|
|
};
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2020-07-28 07:33:51 -04:00
|
|
|
Method* method = _jvf->method();
|
2019-11-22 10:07:21 +00:00
|
|
|
if (getting_receiver()) {
|
2020-07-28 07:33:51 -04:00
|
|
|
if (method->is_static()) {
|
2019-11-22 10:07:21 +00:00
|
|
|
_result = JVMTI_ERROR_INVALID_SLOT;
|
2020-07-31 09:07:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (method->is_native()) {
|
|
|
|
_result = JVMTI_ERROR_OPAQUE_FRAME;
|
|
|
|
return;
|
2010-12-09 15:04:26 -05:00
|
|
|
}
|
|
|
|
|
2020-07-31 09:07:29 +02:00
|
|
|
if (!check_slot_type_no_lvt(_jvf)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (method->has_localvariable_table() &&
|
|
|
|
!check_slot_type_lvt(_jvf)) {
|
|
|
|
return;
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-10 17:46:35 -07:00
|
|
|
InterpreterOopMap oop_mask;
|
|
|
|
_jvf->method()->mask_for(_jvf->bci(), &oop_mask);
|
|
|
|
if (oop_mask.is_dead(_index)) {
|
|
|
|
// The local can be invalid and uninitialized in the scope of current bci
|
|
|
|
_result = JVMTI_ERROR_INVALID_SLOT;
|
|
|
|
return;
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
if (_set) {
|
|
|
|
// Force deoptimization of frame if compiled because it's
|
|
|
|
// possible the compiler emitted some locals as constant values,
|
|
|
|
// meaning they are not mutable.
|
|
|
|
if (can_be_deoptimized(_jvf)) {
|
|
|
|
|
|
|
|
// Schedule deoptimization so that eventually the local
|
|
|
|
// update will be written to an interpreter frame.
|
2010-10-19 16:14:34 -07:00
|
|
|
Deoptimization::deoptimize_frame(_jvf->thread(), _jvf->fr().id());
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Now store a new value for the local which will be applied
|
|
|
|
// once deoptimization occurs. Note however that while this
|
|
|
|
// write is deferred until deoptimization actually happens
|
|
|
|
// can vframe created after this point will have its locals
|
|
|
|
// reflecting this update so as far as anyone can see the
|
|
|
|
// write has already taken place.
|
|
|
|
|
|
|
|
// If we are updating an oop then get the oop from the handle
|
|
|
|
// since the handle will be long gone by the time the deopt
|
|
|
|
// happens. The oop stored in the deferred local will be
|
|
|
|
// gc'd on its own.
|
|
|
|
if (_type == T_OBJECT) {
|
2020-01-24 09:27:07 +01:00
|
|
|
_value.l = cast_from_oop<jobject>(JNIHandles::resolve_external_guard(_value.l));
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
// Re-read the vframe so we can see that it is deoptimized
|
|
|
|
// [ Only need because of assert in update_local() ]
|
|
|
|
_jvf = get_java_vframe();
|
|
|
|
((compiledVFrame*)_jvf)->update_local(_type, _index, _value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
StackValueCollection *locals = _jvf->locals();
|
2020-07-31 09:07:29 +02:00
|
|
|
Thread* current_thread = VMThread::vm_thread();
|
2020-07-30 10:41:31 -04:00
|
|
|
HandleMark hm(current_thread);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
switch (_type) {
|
2010-12-09 15:04:26 -05:00
|
|
|
case T_INT: locals->set_int_at (_index, _value.i); break;
|
|
|
|
case T_LONG: locals->set_long_at (_index, _value.j); break;
|
|
|
|
case T_FLOAT: locals->set_float_at (_index, _value.f); break;
|
|
|
|
case T_DOUBLE: locals->set_double_at(_index, _value.d); break;
|
|
|
|
case T_OBJECT: {
|
2020-07-30 10:41:31 -04:00
|
|
|
Handle ob_h(current_thread, JNIHandles::resolve_external_guard(_value.l));
|
2010-12-09 15:04:26 -05:00
|
|
|
locals->set_obj_at (_index, ob_h);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: ShouldNotReachHere();
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
_jvf->set_locals(locals);
|
|
|
|
} else {
|
2010-12-09 15:04:26 -05:00
|
|
|
if (_jvf->method()->is_native() && _jvf->is_compiled_frame()) {
|
|
|
|
assert(getting_receiver(), "Can only get here when getting receiver");
|
|
|
|
oop receiver = _jvf->fr().get_native_receiver();
|
|
|
|
_value.l = JNIHandles::make_local(_calling_thread, receiver);
|
|
|
|
} else {
|
|
|
|
StackValueCollection *locals = _jvf->locals();
|
|
|
|
|
|
|
|
switch (_type) {
|
|
|
|
case T_INT: _value.i = locals->int_at (_index); break;
|
|
|
|
case T_LONG: _value.j = locals->long_at (_index); break;
|
|
|
|
case T_FLOAT: _value.f = locals->float_at (_index); break;
|
|
|
|
case T_DOUBLE: _value.d = locals->double_at(_index); break;
|
|
|
|
case T_OBJECT: {
|
|
|
|
// Wrap the oop to be returned in a local JNI handle since
|
|
|
|
// oops_do() no longer applies after doit() is finished.
|
|
|
|
oop obj = locals->obj_at(_index)();
|
|
|
|
_value.l = JNIHandles::make_local(_calling_thread, obj);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: ShouldNotReachHere();
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool VM_GetOrSetLocal::allow_nested_vm_operations() const {
|
|
|
|
return true; // May need to deoptimize
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-09 15:04:26 -05:00
|
|
|
VM_GetReceiver::VM_GetReceiver(
|
|
|
|
JavaThread* thread, JavaThread* caller_thread, jint depth)
|
|
|
|
: VM_GetOrSetLocal(thread, caller_thread, depth, 0) {}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//
|
|
|
|
// class JvmtiSuspendControl - see comments in jvmtiImpl.hpp
|
|
|
|
//
|
|
|
|
|
|
|
|
bool JvmtiSuspendControl::suspend(JavaThread *java_thread) {
|
|
|
|
// external suspend should have caught suspending a thread twice
|
|
|
|
|
|
|
|
// Immediate suspension required for JPDA back-end so JVMTI agent threads do
|
|
|
|
// not deadlock due to later suspension on transitions while holding
|
|
|
|
// raw monitors. Passing true causes the immediate suspension.
|
|
|
|
// java_suspend() will catch threads in the process of exiting
|
|
|
|
// and will ignore them.
|
|
|
|
java_thread->java_suspend();
|
|
|
|
|
|
|
|
// It would be nice to have the following assertion in all the time,
|
|
|
|
// but it is possible for a racing resume request to have resumed
|
|
|
|
// this thread right after we suspended it. Temporarily enable this
|
|
|
|
// assertion if you are chasing a different kind of bug.
|
|
|
|
//
|
|
|
|
// assert(java_lang_Thread::thread(java_thread->threadObj()) == NULL ||
|
|
|
|
// java_thread->is_being_ext_suspended(), "thread is not suspended");
|
|
|
|
|
|
|
|
if (java_lang_Thread::thread(java_thread->threadObj()) == NULL) {
|
|
|
|
// check again because we can get delayed in java_suspend():
|
|
|
|
// the thread is in process of exiting.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool JvmtiSuspendControl::resume(JavaThread *java_thread) {
|
|
|
|
// external suspend should have caught resuming a thread twice
|
|
|
|
assert(java_thread->is_being_ext_suspended(), "thread should be suspended");
|
|
|
|
|
|
|
|
// resume thread
|
|
|
|
{
|
|
|
|
// must always grab Threads_lock, see JVM_SuspendThread
|
|
|
|
MutexLocker ml(Threads_lock);
|
|
|
|
java_thread->java_resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void JvmtiSuspendControl::print() {
|
|
|
|
#ifndef PRODUCT
|
2019-09-11 16:25:12 -07:00
|
|
|
ResourceMark rm;
|
2016-04-19 14:14:04 +02:00
|
|
|
LogStreamHandle(Trace, jvmti) log_stream;
|
|
|
|
log_stream.print("Suspended Threads: [");
|
2017-11-22 17:54:50 -08:00
|
|
|
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) {
|
2013-03-06 13:46:55 -05:00
|
|
|
#ifdef JVMTI_TRACE
|
2007-12-01 00:00:00 +00:00
|
|
|
const char *name = JvmtiTrace::safe_get_thread_name(thread);
|
|
|
|
#else
|
|
|
|
const char *name = "";
|
|
|
|
#endif /*JVMTI_TRACE */
|
2016-04-19 14:14:04 +02:00
|
|
|
log_stream.print("%s(%c ", name, thread->is_being_ext_suspended() ? 'S' : '_');
|
2007-12-01 00:00:00 +00:00
|
|
|
if (!thread->has_last_Java_frame()) {
|
2016-04-19 14:14:04 +02:00
|
|
|
log_stream.print("no stack");
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
2016-04-19 14:14:04 +02:00
|
|
|
log_stream.print(") ");
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
2016-04-19 14:14:04 +02:00
|
|
|
log_stream.print_cr("]");
|
2007-12-01 00:00:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
2011-02-02 14:38:01 -05:00
|
|
|
|
|
|
|
JvmtiDeferredEvent JvmtiDeferredEvent::compiled_method_load_event(
|
|
|
|
nmethod* nm) {
|
|
|
|
JvmtiDeferredEvent event = JvmtiDeferredEvent(TYPE_COMPILED_METHOD_LOAD);
|
2011-02-26 13:33:23 -05:00
|
|
|
event._event_data.compiled_method_load = nm;
|
2011-02-02 14:38:01 -05:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
JvmtiDeferredEvent JvmtiDeferredEvent::compiled_method_unload_event(
|
2019-12-04 13:48:38 -05:00
|
|
|
jmethodID id, const void* code) {
|
2011-02-02 14:38:01 -05:00
|
|
|
JvmtiDeferredEvent event = JvmtiDeferredEvent(TYPE_COMPILED_METHOD_UNLOAD);
|
2011-02-26 13:33:23 -05:00
|
|
|
event._event_data.compiled_method_unload.method_id = id;
|
|
|
|
event._event_data.compiled_method_unload.code_begin = code;
|
|
|
|
return event;
|
|
|
|
}
|
2011-04-28 08:24:46 -07:00
|
|
|
|
2011-02-26 13:33:23 -05:00
|
|
|
JvmtiDeferredEvent JvmtiDeferredEvent::dynamic_code_generated_event(
|
|
|
|
const char* name, const void* code_begin, const void* code_end) {
|
|
|
|
JvmtiDeferredEvent event = JvmtiDeferredEvent(TYPE_DYNAMIC_CODE_GENERATED);
|
2011-04-28 08:24:46 -07:00
|
|
|
// Need to make a copy of the name since we don't know how long
|
|
|
|
// the event poster will keep it around after we enqueue the
|
|
|
|
// deferred event and return. strdup() failure is handled in
|
|
|
|
// the post() routine below.
|
|
|
|
event._event_data.dynamic_code_generated.name = os::strdup(name);
|
2011-02-26 13:33:23 -05:00
|
|
|
event._event_data.dynamic_code_generated.code_begin = code_begin;
|
|
|
|
event._event_data.dynamic_code_generated.code_end = code_end;
|
2011-02-02 14:38:01 -05:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2019-12-02 09:02:17 -05:00
|
|
|
JvmtiDeferredEvent JvmtiDeferredEvent::class_unload_event(const char* name) {
|
|
|
|
JvmtiDeferredEvent event = JvmtiDeferredEvent(TYPE_CLASS_UNLOAD);
|
|
|
|
// Need to make a copy of the name since we don't know how long
|
|
|
|
// the event poster will keep it around after we enqueue the
|
|
|
|
// deferred event and return. strdup() failure is handled in
|
|
|
|
// the post() routine below.
|
|
|
|
event._event_data.class_unload.name = os::strdup(name);
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2011-02-02 14:38:01 -05:00
|
|
|
void JvmtiDeferredEvent::post() {
|
2019-12-02 08:40:52 -05:00
|
|
|
assert(Thread::current()->is_service_thread(),
|
2011-02-26 13:33:23 -05:00
|
|
|
"Service thread must post enqueued events");
|
2011-02-02 14:38:01 -05:00
|
|
|
switch(_type) {
|
2011-02-26 13:33:23 -05:00
|
|
|
case TYPE_COMPILED_METHOD_LOAD: {
|
|
|
|
nmethod* nm = _event_data.compiled_method_load;
|
|
|
|
JvmtiExport::post_compiled_method_load(nm);
|
2011-02-02 14:38:01 -05:00
|
|
|
break;
|
2011-02-26 13:33:23 -05:00
|
|
|
}
|
2011-03-15 06:37:31 -07:00
|
|
|
case TYPE_COMPILED_METHOD_UNLOAD: {
|
2011-02-02 14:38:01 -05:00
|
|
|
JvmtiExport::post_compiled_method_unload(
|
2011-02-26 13:33:23 -05:00
|
|
|
_event_data.compiled_method_unload.method_id,
|
|
|
|
_event_data.compiled_method_unload.code_begin);
|
2011-02-02 14:38:01 -05:00
|
|
|
break;
|
2011-03-15 06:37:31 -07:00
|
|
|
}
|
2011-04-28 08:24:46 -07:00
|
|
|
case TYPE_DYNAMIC_CODE_GENERATED: {
|
2011-02-26 13:33:23 -05:00
|
|
|
JvmtiExport::post_dynamic_code_generated_internal(
|
2011-04-28 08:24:46 -07:00
|
|
|
// if strdup failed give the event a default name
|
|
|
|
(_event_data.dynamic_code_generated.name == NULL)
|
|
|
|
? "unknown_code" : _event_data.dynamic_code_generated.name,
|
2011-02-26 13:33:23 -05:00
|
|
|
_event_data.dynamic_code_generated.code_begin,
|
|
|
|
_event_data.dynamic_code_generated.code_end);
|
2011-04-28 08:24:46 -07:00
|
|
|
if (_event_data.dynamic_code_generated.name != NULL) {
|
|
|
|
// release our copy
|
|
|
|
os::free((void *)_event_data.dynamic_code_generated.name);
|
|
|
|
}
|
2011-02-02 14:38:01 -05:00
|
|
|
break;
|
2011-04-28 08:24:46 -07:00
|
|
|
}
|
2019-12-02 09:02:17 -05:00
|
|
|
case TYPE_CLASS_UNLOAD: {
|
|
|
|
JvmtiExport::post_class_unload_internal(
|
|
|
|
// if strdup failed give the event a default name
|
|
|
|
(_event_data.class_unload.name == NULL)
|
|
|
|
? "unknown_class" : _event_data.class_unload.name);
|
|
|
|
if (_event_data.class_unload.name != NULL) {
|
|
|
|
// release our copy
|
|
|
|
os::free((void *)_event_data.class_unload.name);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-02-02 14:38:01 -05:00
|
|
|
default:
|
|
|
|
ShouldNotReachHere();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-05 16:57:17 -05:00
|
|
|
void JvmtiDeferredEvent::post_compiled_method_load_event(JvmtiEnv* env) {
|
|
|
|
assert(_type == TYPE_COMPILED_METHOD_LOAD, "only user of this method");
|
|
|
|
nmethod* nm = _event_data.compiled_method_load;
|
|
|
|
JvmtiExport::post_compiled_method_load(env, nm);
|
|
|
|
}
|
|
|
|
|
2019-12-18 11:51:22 -05:00
|
|
|
void JvmtiDeferredEvent::run_nmethod_entry_barriers() {
|
|
|
|
if (_type == TYPE_COMPILED_METHOD_LOAD) {
|
|
|
|
_event_data.compiled_method_load->run_nmethod_entry_barrier();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-05 16:57:17 -05:00
|
|
|
|
2019-12-02 08:40:52 -05:00
|
|
|
// Keep the nmethod for compiled_method_load from being unloaded.
|
|
|
|
void JvmtiDeferredEvent::oops_do(OopClosure* f, CodeBlobClosure* cf) {
|
|
|
|
if (cf != NULL && _type == TYPE_COMPILED_METHOD_LOAD) {
|
|
|
|
cf->do_code_blob(_event_data.compiled_method_load);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The sweeper calls this and marks the nmethods here on the stack so that
|
|
|
|
// they cannot be turned into zombies while in the queue.
|
|
|
|
void JvmtiDeferredEvent::nmethods_do(CodeBlobClosure* cf) {
|
|
|
|
if (cf != NULL && _type == TYPE_COMPILED_METHOD_LOAD) {
|
|
|
|
cf->do_code_blob(_event_data.compiled_method_load);
|
2019-12-05 16:57:17 -05:00
|
|
|
}
|
2019-12-02 08:40:52 -05:00
|
|
|
}
|
|
|
|
|
2019-12-18 11:51:22 -05:00
|
|
|
|
2011-02-02 14:38:01 -05:00
|
|
|
bool JvmtiDeferredEventQueue::has_events() {
|
2019-12-18 11:51:22 -05:00
|
|
|
// We save the queued events before the live phase and post them when it starts.
|
|
|
|
// This code could skip saving the events on the queue before the live
|
|
|
|
// phase and ignore them, but this would change how we do things now.
|
|
|
|
// Starting the service thread earlier causes this to be called before the live phase begins.
|
|
|
|
// The events on the queue should all be posted after the live phase so this is an
|
|
|
|
// ok check. Before the live phase, DynamicCodeGenerated events are posted directly.
|
|
|
|
// If we add other types of events to the deferred queue, this could get ugly.
|
|
|
|
return JvmtiEnvBase::get_phase() == JVMTI_PHASE_LIVE && _queue_head != NULL;
|
2011-02-02 14:38:01 -05:00
|
|
|
}
|
|
|
|
|
2019-12-05 16:57:17 -05:00
|
|
|
void JvmtiDeferredEventQueue::enqueue(JvmtiDeferredEvent event) {
|
2011-02-02 14:38:01 -05:00
|
|
|
// Events get added to the end of the queue (and are pulled off the front).
|
|
|
|
QueueNode* node = new QueueNode(event);
|
|
|
|
if (_queue_tail == NULL) {
|
|
|
|
_queue_tail = _queue_head = node;
|
|
|
|
} else {
|
|
|
|
assert(_queue_tail->next() == NULL, "Must be the last element in the list");
|
|
|
|
_queue_tail->set_next(node);
|
|
|
|
_queue_tail = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert((_queue_head == NULL) == (_queue_tail == NULL),
|
|
|
|
"Inconsistent queue markers");
|
|
|
|
}
|
|
|
|
|
|
|
|
JvmtiDeferredEvent JvmtiDeferredEventQueue::dequeue() {
|
|
|
|
assert(_queue_head != NULL, "Nothing to dequeue");
|
|
|
|
|
|
|
|
if (_queue_head == NULL) {
|
|
|
|
// Just in case this happens in product; it shouldn't but let's not crash
|
|
|
|
return JvmtiDeferredEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
QueueNode* node = _queue_head;
|
|
|
|
_queue_head = _queue_head->next();
|
|
|
|
if (_queue_head == NULL) {
|
|
|
|
_queue_tail = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert((_queue_head == NULL) == (_queue_tail == NULL),
|
|
|
|
"Inconsistent queue markers");
|
|
|
|
|
|
|
|
JvmtiDeferredEvent event = node->event();
|
|
|
|
delete node;
|
|
|
|
return event;
|
|
|
|
}
|
2019-12-02 08:40:52 -05:00
|
|
|
|
2019-12-05 16:57:17 -05:00
|
|
|
void JvmtiDeferredEventQueue::post(JvmtiEnv* env) {
|
|
|
|
// Post and destroy queue nodes
|
|
|
|
while (_queue_head != NULL) {
|
|
|
|
JvmtiDeferredEvent event = dequeue();
|
|
|
|
event.post_compiled_method_load_event(env);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-18 11:51:22 -05:00
|
|
|
void JvmtiDeferredEventQueue::run_nmethod_entry_barriers() {
|
|
|
|
for(QueueNode* node = _queue_head; node != NULL; node = node->next()) {
|
|
|
|
node->event().run_nmethod_entry_barriers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-02 08:40:52 -05:00
|
|
|
void JvmtiDeferredEventQueue::oops_do(OopClosure* f, CodeBlobClosure* cf) {
|
|
|
|
for(QueueNode* node = _queue_head; node != NULL; node = node->next()) {
|
|
|
|
node->event().oops_do(f, cf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void JvmtiDeferredEventQueue::nmethods_do(CodeBlobClosure* cf) {
|
|
|
|
for(QueueNode* node = _queue_head; node != NULL; node = node->next()) {
|
|
|
|
node->event().nmethods_do(cf);
|
|
|
|
}
|
|
|
|
}
|