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 <inttypes.h>
18 
19 #include "android-base/logging.h"
20 #include "android-base/macros.h"
21 #include "android-base/stringprintf.h"
22 #include "jni.h"
23 #include "jvmti.h"
24 #include "scoped_utf_chars.h"
25 
26 // Test infrastructure
27 #include "jvmti_helper.h"
28 #include "test_env.h"
29 
30 namespace art {
31 namespace Test929Search {
32 
Java_Main_addToBootClassLoader(JNIEnv * env,jclass Main_klass ATTRIBUTE_UNUSED,jstring segment)33 extern "C" JNIEXPORT void JNICALL Java_Main_addToBootClassLoader(
34     JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jstring segment) {
35   ScopedUtfChars utf(env, segment);
36   if (utf.c_str() == nullptr) {
37     return;
38   }
39   jvmtiError result = jvmti_env->AddToBootstrapClassLoaderSearch(utf.c_str());
40   JvmtiErrorToException(env, jvmti_env, result);
41 }
42 
Java_Main_addToSystemClassLoader(JNIEnv * env,jclass Main_klass ATTRIBUTE_UNUSED,jstring segment)43 extern "C" JNIEXPORT void JNICALL Java_Main_addToSystemClassLoader(
44     JNIEnv* env, jclass Main_klass ATTRIBUTE_UNUSED, jstring segment) {
45   ScopedUtfChars utf(env, segment);
46   if (utf.c_str() == nullptr) {
47     return;
48   }
49   jvmtiError result = jvmti_env->AddToSystemClassLoaderSearch(utf.c_str());
50   JvmtiErrorToException(env, jvmti_env, result);
51 }
52 
53 }  // namespace Test929Search
54 }  // namespace art
55