1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <atomic> 18 #include <signal.h> 19 #include <sys/types.h> 20 21 #include "android-base/logging.h" 22 #include "android-base/macros.h" 23 #include "jni.h" 24 #include "jvmti.h" 25 26 // Test infrastructure 27 #include "jvmti_helper.h" 28 #include "test_env.h" 29 30 namespace art { 31 namespace Test933MiscEvents { 32 33 static std::atomic<bool> saw_dump_request(false); 34 35 static void DumpRequestCallback(jvmtiEnv* jenv ATTRIBUTE_UNUSED) { 36 printf("Received dump request.\n"); 37 saw_dump_request.store(true, std::memory_order::memory_order_relaxed); 38 } 39 40 extern "C" JNIEXPORT void JNICALL Java_art_Test933_testSigQuit( 41 JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED) { 42 jvmtiEventCallbacks callbacks; 43 memset(&callbacks, 0, sizeof(jvmtiEventCallbacks)); 44 callbacks.DataDumpRequest = DumpRequestCallback; 45 jvmtiError ret = jvmti_env->SetEventCallbacks(&callbacks, sizeof(callbacks)); 46 if (JvmtiErrorToException(env, jvmti_env, ret)) { 47 return; 48 } 49 50 ret = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, 51 JVMTI_EVENT_DATA_DUMP_REQUEST, 52 nullptr); 53 if (JvmtiErrorToException(env, jvmti_env, ret)) { 54 return; 55 } 56 57 // Send sigquit to self. 58 kill(getpid(), SIGQUIT); 59 60 // Busy-wait for request. 61 for (;;) { 62 sleep(1); 63 if (saw_dump_request.load(std::memory_order::memory_order_relaxed)) { 64 break; 65 } 66 } 67 68 ret = jvmti_env->SetEventNotificationMode(JVMTI_DISABLE, JVMTI_EVENT_DATA_DUMP_REQUEST, nullptr); 69 JvmtiErrorToException(env, jvmti_env, ret); 70 } 71 72 } // namespace Test933MiscEvents 73 } // namespace art 74