Common functionality for WorldBuilder implementations.
| 49 | * Common functionality for {@link WorldBuilder} implementations. |
| 50 | */ |
| 51 | public abstract class AbstractWorldBuilder implements WorldBuilder { |
| 52 | |
| 53 | private static final Logger logger = LogManager.getLogger(AbstractWorldBuilder.class); |
| 54 | |
| 55 | protected static final String JREs = "java-benchmarks/JREs"; |
| 56 | |
| 57 | protected static final List<String> implicitEntries = List.of( |
| 58 | "<java.lang.System: void initializeSystemClass()>", |
| 59 | "<java.lang.Thread: void <init>(java.lang.ThreadGroup,java.lang.Runnable)>", |
| 60 | "<java.lang.Thread: void <init>(java.lang.ThreadGroup,java.lang.String)>", |
| 61 | "<java.lang.Thread: void exit()>", |
| 62 | "<java.lang.ThreadGroup: void <init>()>", |
| 63 | "<java.lang.ThreadGroup: void <init>(java.lang.ThreadGroup,java.lang.String)>", |
| 64 | "<java.lang.ThreadGroup: void uncaughtException(java.lang.Thread,java.lang.Throwable)>", |
| 65 | "<java.lang.ClassLoader: void <init>()>", |
| 66 | "<java.lang.ClassLoader: java.lang.Class loadClassInternal(java.lang.String)>", |
| 67 | "<java.lang.ClassLoader: void checkPackageAccess(java.lang.Class,java.security.ProtectionDomain)>", |
| 68 | "<java.lang.ClassLoader: void addClass(java.lang.Class)>", |
| 69 | "<java.lang.ClassLoader: long findNative(java.lang.ClassLoader,java.lang.String)>", |
| 70 | "<java.security.PrivilegedActionException: void <init>(java.lang.Exception)>" |
| 71 | ); |
| 72 | |
| 73 | protected static String getClassPath(Options options) { |
| 74 | Set<String> jars = new HashSet<>(); |
| 75 | options.getClassPath().forEach(classPath -> { |
| 76 | try (Stream<Path> paths = Files.walk(Path.of(classPath))) { |
| 77 | paths.map(Path::toString).filter(p -> p.endsWith(".jar") && hasClasspathKey(p, options.getClasspathKeywords())).forEach(jars::add); |
| 78 | } catch (IOException e) { |
| 79 | |
| 80 | } |
| 81 | }); |
| 82 | options.getAppClassPath().forEach(classPath -> { |
| 83 | try (Stream<Path> paths = Files.walk(Path.of(classPath))) { |
| 84 | paths.map(Path::toString).filter(p -> p.endsWith(".jar") && hasClasspathKey(p, options.getClasspathKeywords())).forEach(jars::add); |
| 85 | } catch (IOException e) { |
| 86 | |
| 87 | } |
| 88 | }); |
| 89 | if (options.isPrependJVM()) { |
| 90 | return Streams.concat( |
| 91 | options.getAppClassPath().stream(), |
| 92 | options.getClassPath().stream(), |
| 93 | jars.stream()) |
| 94 | .collect(Collectors.joining(File.pathSeparator)); |
| 95 | } else { // when prependJVM is not set, we manually specify JRE jars |
| 96 | // check existence of JREs |
| 97 | File jreDir = new File(JREs); |
| 98 | if (!jreDir.exists()) { |
| 99 | throw new RuntimeException(""" |
| 100 | Failed to locate Java library. |
| 101 | Please clone submodule 'java-benchmarks' by command: |
| 102 | 'git submodule update --init --recursive' (if you are running Tai-e) |
| 103 | or 'git clone https://github.com/pascal-lab/java-benchmarks' (if you are using Tai-e as a dependency), |
| 104 | then put it in Tai-e's working directory."""); |
| 105 | } |
| 106 | String jrePath = String.format("%s/jre1.%d", |
| 107 | JREs, options.getJavaVersion()); |
| 108 | try (Stream<Path> paths = Files.walk(Path.of(jrePath))) { |