Andreas Gampe | 336c3c3 | 2016-11-08 17:02:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #ifndef ART_TEST_TI_AGENT_COMMON_HELPER_H_ |
| 18 | #define ART_TEST_TI_AGENT_COMMON_HELPER_H_ |
| 19 | |
| 20 | #include "jni.h" |
Alex Light | 1e07ca6 | 2016-12-02 11:40:56 -0800 | [diff] [blame] | 21 | #include "openjdkjvmti/jvmti.h" |
Andreas Gampe | 336c3c3 | 2016-11-08 17:02:19 -0800 | [diff] [blame] | 22 | #include "ScopedLocalRef.h" |
| 23 | |
| 24 | namespace art { |
Alex Light | 1e07ca6 | 2016-12-02 11:40:56 -0800 | [diff] [blame] | 25 | namespace common_redefine { |
| 26 | |
| 27 | jint OnLoad(JavaVM* vm, char* options, void* reserved); |
| 28 | |
| 29 | } // namespace common_redefine |
| 30 | |
| 31 | extern bool RuntimeIsJVM; |
| 32 | |
| 33 | bool IsJVM(); |
Andreas Gampe | 336c3c3 | 2016-11-08 17:02:19 -0800 | [diff] [blame] | 34 | |
| 35 | template <typename T> |
| 36 | static jobjectArray CreateObjectArray(JNIEnv* env, |
| 37 | jint length, |
| 38 | const char* component_type_descriptor, |
| 39 | T src) { |
| 40 | if (length < 0) { |
| 41 | return nullptr; |
| 42 | } |
| 43 | |
| 44 | ScopedLocalRef<jclass> obj_class(env, env->FindClass(component_type_descriptor)); |
| 45 | if (obj_class.get() == nullptr) { |
| 46 | return nullptr; |
| 47 | } |
| 48 | |
| 49 | ScopedLocalRef<jobjectArray> ret(env, env->NewObjectArray(length, obj_class.get(), nullptr)); |
| 50 | if (ret.get() == nullptr) { |
| 51 | return nullptr; |
| 52 | } |
| 53 | |
| 54 | for (jint i = 0; i < length; ++i) { |
| 55 | jobject element = src(i); |
| 56 | env->SetObjectArrayElement(ret.get(), static_cast<jint>(i), element); |
| 57 | env->DeleteLocalRef(element); |
| 58 | if (env->ExceptionCheck()) { |
| 59 | return nullptr; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return ret.release(); |
| 64 | } |
| 65 | |
Alex Light | 1e07ca6 | 2016-12-02 11:40:56 -0800 | [diff] [blame] | 66 | void SetAllCapabilities(jvmtiEnv* env); |
Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 67 | |
Andreas Gampe | 1bdaf73 | 2017-01-09 19:21:06 -0800 | [diff] [blame^] | 68 | bool JvmtiErrorToException(JNIEnv* env, jvmtiError error); |
| 69 | |
Andreas Gampe | 336c3c3 | 2016-11-08 17:02:19 -0800 | [diff] [blame] | 70 | } // namespace art |
| 71 | |
| 72 | #endif // ART_TEST_TI_AGENT_COMMON_HELPER_H_ |