blob: 642ca032746df18a789dd0c60fd2443c21760177 [file] [log] [blame]
Andreas Gampe336c3c32016-11-08 17:02:19 -08001/*
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 Light1e07ca62016-12-02 11:40:56 -080021#include "openjdkjvmti/jvmti.h"
Andreas Gampe336c3c32016-11-08 17:02:19 -080022#include "ScopedLocalRef.h"
23
24namespace art {
Alex Light1e07ca62016-12-02 11:40:56 -080025namespace common_redefine {
26
27jint OnLoad(JavaVM* vm, char* options, void* reserved);
28
29} // namespace common_redefine
30
31extern bool RuntimeIsJVM;
32
33bool IsJVM();
Andreas Gampe336c3c32016-11-08 17:02:19 -080034
35template <typename T>
36static 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 Light1e07ca62016-12-02 11:40:56 -080066void SetAllCapabilities(jvmtiEnv* env);
Alex Lighte6574242016-08-17 09:56:24 -070067
Andreas Gampe1bdaf732017-01-09 19:21:06 -080068bool JvmtiErrorToException(JNIEnv* env, jvmtiError error);
69
Andreas Gampe336c3c32016-11-08 17:02:19 -080070} // namespace art
71
72#endif // ART_TEST_TI_AGENT_COMMON_HELPER_H_