blob: 23cea83be688f89174fc36f43d98976704de4dde [file] [log] [blame]
Andreas Gampecefaa142017-01-23 15:04:59 -08001/*
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 "search_onload.h"
18
19#include <inttypes.h>
20
Andreas Gampe57943812017-12-06 21:39:13 -080021#include <android-base/macros.h>
22#include <android-base/stringprintf.h>
23
Andreas Gampecefaa142017-01-23 15:04:59 -080024#include "base/macros.h"
25#include "jni.h"
Andreas Gampe5e03a302017-03-13 13:10:00 -070026#include "jvmti.h"
Andreas Gampe027444b2017-03-31 12:49:07 -070027#include "scoped_utf_chars.h"
Andreas Gampecefaa142017-01-23 15:04:59 -080028
Andreas Gampe3f46c962017-03-30 10:26:59 -070029// Test infrastructure
30#include "jvmti_helper.h"
31#include "test_env.h"
Andreas Gampecefaa142017-01-23 15:04:59 -080032
33namespace art {
34namespace Test936SearchOnload {
35
36jint OnLoad(JavaVM* vm,
37 char* options ATTRIBUTE_UNUSED,
38 void* reserved ATTRIBUTE_UNUSED) {
39 if (vm->GetEnv(reinterpret_cast<void**>(&jvmti_env), JVMTI_VERSION_1_0)) {
40 printf("Unable to get jvmti env!\n");
41 return 1;
42 }
Alex Light3d324fd2017-07-20 15:38:52 -070043 SetStandardCapabilities(jvmti_env);
Andreas Gampecefaa142017-01-23 15:04:59 -080044
45 char* dex_loc = getenv("DEX_LOCATION");
46 std::string dex1 = android::base::StringPrintf("%s/936-search-onload.jar", dex_loc);
47 std::string dex2 = android::base::StringPrintf("%s/936-search-onload-ex.jar", dex_loc);
48
49 jvmtiError result = jvmti_env->AddToBootstrapClassLoaderSearch(dex1.c_str());
50 if (result != JVMTI_ERROR_NONE) {
51 printf("Could not add to bootstrap classloader.\n");
52 return 1;
53 }
54
55 result = jvmti_env->AddToSystemClassLoaderSearch(dex2.c_str());
56 if (result != JVMTI_ERROR_NONE) {
57 printf("Could not add to system classloader.\n");
58 return 1;
59 }
60
61 return JNI_OK;
62}
63
64} // namespace Test936SearchOnload
65} // namespace art