summaryrefslogtreecommitdiff
path: root/tools/dump-jvmti-state/dump-jvmti.cc
diff options
context:
space:
mode:
author Nicolas Geoffray <ngeoffray@google.com> 2019-03-12 14:25:32 +0000
committer Nicolas Geoffray <ngeoffray@google.com> 2019-03-12 14:25:54 +0000
commita55e8b5c9827cc4dc4e7f7c7ee07ef1fdafc35e0 (patch)
tree48120329529bfa5e3e20c1726a513488f97c354e /tools/dump-jvmti-state/dump-jvmti.cc
parent403aafa9f286e13ee2a64748514d33af39b55ab0 (diff)
Revert "Revert^2 "Add extension and agent for dumping internal jvmti plugin data.""
This reverts commit 2d8b8119228bbe4202490b1d5fed6191989d5d83. Reason for revert: Fails jdwp tests. Change-Id: I0577fd82df161183ccd73eaf61cbe6bf871ef410
Diffstat (limited to 'tools/dump-jvmti-state/dump-jvmti.cc')
-rw-r--r--tools/dump-jvmti-state/dump-jvmti.cc115
1 files changed, 0 insertions, 115 deletions
diff --git a/tools/dump-jvmti-state/dump-jvmti.cc b/tools/dump-jvmti-state/dump-jvmti.cc
deleted file mode 100644
index 71a0115999..0000000000
--- a/tools/dump-jvmti-state/dump-jvmti.cc
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright (C) 2019 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-#include <android-base/logging.h>
-
-#include <jni.h>
-#include <jvmti.h>
-
-namespace dumpjvmti {
-
-namespace {
-
-// Special art ti-version number. We will use this as a fallback if we cannot get a regular JVMTI
-// env.
-static constexpr jint kArtTiVersion = JVMTI_VERSION_1_2 | 0x40000000;
-
-template <typename T> static void Dealloc(jvmtiEnv* env, T* t) {
- env->Deallocate(reinterpret_cast<unsigned char*>(t));
-}
-
-template <typename T, typename... Rest> static void Dealloc(jvmtiEnv* env, T* t, Rest... rs) {
- Dealloc(env, t);
- Dealloc(env, rs...);
-}
-
-static void DeallocParams(jvmtiEnv* env, jvmtiParamInfo* params, jint n_params) {
- for (jint i = 0; i < n_params; i++) {
- Dealloc(env, params[i].name);
- }
-}
-
-// The extension function to get the internal data
-static jvmtiError (*GetInternalData)(jvmtiEnv* env, unsigned char** data) = nullptr;
-
-static jint SetupJvmtiEnv(JavaVM* vm, jvmtiEnv** jvmti) {
- jint res = 0;
- res = vm->GetEnv(reinterpret_cast<void**>(jvmti), JVMTI_VERSION_1_1);
-
- if (res != JNI_OK || *jvmti == nullptr) {
- LOG(ERROR) << "Unable to access JVMTI, error code " << res;
- res = vm->GetEnv(reinterpret_cast<void**>(jvmti), kArtTiVersion);
- if (res != JNI_OK) {
- return res;
- }
- }
-
- jvmtiEnv* env = *jvmti;
-
- // Get the extensions.
- jint n_ext = 0;
- jvmtiExtensionFunctionInfo* infos = nullptr;
- if (env->GetExtensionFunctions(&n_ext, &infos) != JVMTI_ERROR_NONE) {
- return JNI_ERR;
- }
- for (jint i = 0; i < n_ext; i++) {
- jvmtiExtensionFunctionInfo* cur_info = &infos[i];
- if (strcmp("com.android.art.misc.get_plugin_internal_state", cur_info->id) == 0) {
- GetInternalData = reinterpret_cast<decltype(GetInternalData)>(cur_info->func);
- }
- // Cleanup the cur_info
- DeallocParams(env, cur_info->params, cur_info->param_count);
- Dealloc(env, cur_info->id, cur_info->short_description, cur_info->params, cur_info->errors);
- }
- // Cleanup the array.
- Dealloc(env, infos);
- return GetInternalData != nullptr ? JNI_OK : JNI_ERR;
-}
-
-static void CbDataDump(jvmtiEnv* jvmti) {
- unsigned char* data = nullptr;
- if (JVMTI_ERROR_NONE == GetInternalData(jvmti, &data)) {
- LOG(INFO) << data;
- Dealloc(jvmti, data);
- }
-}
-
-} // namespace
-
-static jint AgentStart(JavaVM* vm, char* options ATTRIBUTE_UNUSED, void* reserved ATTRIBUTE_UNUSED) {
- jvmtiEnv* jvmti = nullptr;
- if (SetupJvmtiEnv(vm, &jvmti) != JNI_OK) {
- LOG(ERROR) << "Could not get JVMTI env or ArtTiEnv!";
- return JNI_ERR;
- }
- jvmtiEventCallbacks cb{
- .DataDumpRequest = CbDataDump,
- };
- jvmti->SetEventCallbacks(&cb, sizeof(cb));
- jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_DATA_DUMP_REQUEST, nullptr);
- return JNI_OK;
-}
-
-// Late attachment (e.g. 'am attach-agent').
-extern "C" JNIEXPORT jint JNICALL Agent_OnAttach(JavaVM* vm, char* options, void* reserved) {
- return AgentStart(vm, options, reserved);
-}
-
-// Early attachment
-extern "C" JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM* jvm, char* options, void* reserved) {
- return AgentStart(jvm, options, reserved);
-}
-
-} // namespace dumpjvmti