blob: 2286a467d3eeb85ec6fa58bbbdc7261df446a117 [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
21#include "android-base/stringprintf.h"
22#include "base/logging.h"
23#include "base/macros.h"
24#include "jni.h"
25#include "openjdkjvmti/jvmti.h"
26#include "ScopedUtfChars.h"
27
28#include "ti-agent/common_helper.h"
29#include "ti-agent/common_load.h"
30
31namespace art {
32namespace Test936SearchOnload {
33
34jint OnLoad(JavaVM* vm,
35 char* options ATTRIBUTE_UNUSED,
36 void* reserved ATTRIBUTE_UNUSED) {
37 if (vm->GetEnv(reinterpret_cast<void**>(&jvmti_env), JVMTI_VERSION_1_0)) {
38 printf("Unable to get jvmti env!\n");
39 return 1;
40 }
41 SetAllCapabilities(jvmti_env);
42
43 char* dex_loc = getenv("DEX_LOCATION");
44 std::string dex1 = android::base::StringPrintf("%s/936-search-onload.jar", dex_loc);
45 std::string dex2 = android::base::StringPrintf("%s/936-search-onload-ex.jar", dex_loc);
46
47 jvmtiError result = jvmti_env->AddToBootstrapClassLoaderSearch(dex1.c_str());
48 if (result != JVMTI_ERROR_NONE) {
49 printf("Could not add to bootstrap classloader.\n");
50 return 1;
51 }
52
53 result = jvmti_env->AddToSystemClassLoaderSearch(dex2.c_str());
54 if (result != JVMTI_ERROR_NONE) {
55 printf("Could not add to system classloader.\n");
56 return 1;
57 }
58
59 return JNI_OK;
60}
61
62} // namespace Test936SearchOnload
63} // namespace art