Add JVMTI DDMS extension method and event.
Add a new jvmti extension method
'com.android.art.internal.ddm.process_chunk' that can be used to
request that the system process a DDMS chunk with a given type and
data payload. It returns the processed chunk type and data. Agents can
use this to interact with DDMS.
Also add a new jvmti extension event
'com.android.art.internal.ddm.publish_chunk' that will be called
whenever the system wishes to send an unrequested chunk of data to be
processed. This is triggered by code executing 'DdmServer#sendChunk'
or by other internal mechanisms.
Both of these extensions are provided mainly to aid in the maintenence
of backwards compatibility with existing DDMS applications. Generally
agents should prefer to use the normal JVMTI events and controls over
interpreting DDMS data or calling DDMS functions.
Bug: 62821960
Test: ./test.py --host -j50
Test: ./art/tools/run-jdwp-tests.sh --mode=host \
--test org.apache.harmony.jpda.tests.jdwp.DDM.DDMTest
Change-Id: I39f22d3d096d12b59713ec7b8b0c08d0d68ff422
diff --git a/openjdkjvmti/events.cc b/openjdkjvmti/events.cc
index 6a64441..d1d606d 100644
--- a/openjdkjvmti/events.cc
+++ b/openjdkjvmti/events.cc
@@ -60,6 +60,45 @@
namespace openjdkjvmti {
+void ArtJvmtiEventCallbacks::CopyExtensionsFrom(const ArtJvmtiEventCallbacks* cb) {
+ if (art::kIsDebugBuild) {
+ ArtJvmtiEventCallbacks clean;
+ DCHECK_EQ(memcmp(&clean, this, sizeof(clean)), 0)
+ << "CopyExtensionsFrom called with initialized eventsCallbacks!";
+ }
+ if (cb != nullptr) {
+ memcpy(this, cb, sizeof(*this));
+ } else {
+ memset(this, 0, sizeof(*this));
+ }
+}
+
+jvmtiError ArtJvmtiEventCallbacks::Set(jint index, jvmtiExtensionEvent cb) {
+ switch (index) {
+ case static_cast<jint>(ArtJvmtiEvent::kDdmPublishChunk):
+ DdmPublishChunk = reinterpret_cast<ArtJvmtiEventDdmPublishChunk>(cb);
+ return OK;
+ default:
+ return ERR(ILLEGAL_ARGUMENT);
+ }
+}
+
+
+bool IsExtensionEvent(jint e) {
+ return e >= static_cast<jint>(ArtJvmtiEvent::kMinEventTypeVal) &&
+ e <= static_cast<jint>(ArtJvmtiEvent::kMaxEventTypeVal) &&
+ IsExtensionEvent(static_cast<ArtJvmtiEvent>(e));
+}
+
+bool IsExtensionEvent(ArtJvmtiEvent e) {
+ switch (e) {
+ case ArtJvmtiEvent::kDdmPublishChunk:
+ return true;
+ default:
+ return false;
+ }
+}
+
bool EventMasks::IsEnabledAnywhere(ArtJvmtiEvent event) {
return global_event_mask.Test(event) || unioned_thread_event_mask.Test(event);
}
@@ -213,6 +252,38 @@
args...);
}
+static void SetupDdmTracking(art::DdmCallback* listener, bool enable) {
+ art::ScopedObjectAccess soa(art::Thread::Current());
+ if (enable) {
+ art::Runtime::Current()->GetRuntimeCallbacks()->AddDdmCallback(listener);
+ } else {
+ art::Runtime::Current()->GetRuntimeCallbacks()->RemoveDdmCallback(listener);
+ }
+}
+
+class JvmtiDdmChunkListener : public art::DdmCallback {
+ public:
+ explicit JvmtiDdmChunkListener(EventHandler* handler) : handler_(handler) {}
+
+ void DdmPublishChunk(uint32_t type, const art::ArrayRef<const uint8_t>& data)
+ OVERRIDE REQUIRES_SHARED(art::Locks::mutator_lock_) {
+ if (handler_->IsEventEnabledAnywhere(ArtJvmtiEvent::kDdmPublishChunk)) {
+ art::Thread* self = art::Thread::Current();
+ handler_->DispatchEvent<ArtJvmtiEvent::kDdmPublishChunk>(
+ self,
+ static_cast<JNIEnv*>(self->GetJniEnv()),
+ static_cast<jint>(type),
+ static_cast<jint>(data.size()),
+ reinterpret_cast<const jbyte*>(data.data()));
+ }
+ }
+
+ private:
+ EventHandler* handler_;
+
+ DISALLOW_COPY_AND_ASSIGN(JvmtiDdmChunkListener);
+};
+
class JvmtiAllocationListener : public art::gc::AllocationListener {
public:
explicit JvmtiAllocationListener(EventHandler* handler) : handler_(handler) {}
@@ -924,6 +995,9 @@
// Handle special work for the given event type, if necessary.
void EventHandler::HandleEventType(ArtJvmtiEvent event, bool enable) {
switch (event) {
+ case ArtJvmtiEvent::kDdmPublishChunk:
+ SetupDdmTracking(ddm_listener_.get(), enable);
+ return;
case ArtJvmtiEvent::kVmObjectAlloc:
SetupObjectAllocationTracking(alloc_listener_.get(), enable);
return;
@@ -1104,6 +1178,7 @@
EventHandler::EventHandler() {
alloc_listener_.reset(new JvmtiAllocationListener(this));
+ ddm_listener_.reset(new JvmtiDdmChunkListener(this));
gc_pause_listener_.reset(new JvmtiGcPauseListener(this));
method_trace_listener_.reset(new JvmtiMethodTraceListener(this));
monitor_listener_.reset(new JvmtiMonitorListener(this));