• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import java.io.File;
18 import java.lang.reflect.Method;
19 import java.util.Arrays;
20 
21 public class Main {
main(String[] args)22   public static void main(String[] args) throws Exception {
23     // Check whether we get the BootClassLoader (not null).
24     ClassLoader bootClassLoader = Object.class.getClassLoader();
25     if (bootClassLoader == null) {
26       throw new IllegalStateException("Expected non-null classloader for Object");
27     }
28 
29     // Try to load libarttest(d) with the BootClassLoader. First construct the
30     // filename. It's in NATIVELOADER_DEFAULT_NAMESPACE_LIBS, so it's accessible
31     // simply through the file name.
32     String libName = System.mapLibraryName(args[0]);
33 
34     // Then call an internal function that accepts the classloader. Do not use load(), as it
35     // is deprecated and only there for backwards compatibility, and prints a warning to the
36     // log that we'd have to strip (it contains the pid).
37     Method m = Runtime.class.getDeclaredMethod("nativeLoad", String.class, ClassLoader.class);
38     m.setAccessible(true);
39     Object result = m.invoke(Runtime.getRuntime(), libName, bootClassLoader);
40     if (result != null) {
41       throw new IllegalStateException(result.toString());
42     }
43 
44     System.out.println("Success.");
45   }
46 }
47