diff options
Diffstat (limited to 'caliper/src/main/java/com')
4 files changed, 36 insertions, 7 deletions
diff --git a/caliper/src/main/java/com/google/caliper/config/VmConfig.java b/caliper/src/main/java/com/google/caliper/config/VmConfig.java index fcb63ca..599fa69 100644 --- a/caliper/src/main/java/com/google/caliper/config/VmConfig.java +++ b/caliper/src/main/java/com/google/caliper/config/VmConfig.java @@ -79,8 +79,8 @@ public final class VmConfig { return platform.name(); } - public String workerClassPath() { - return platform.workerClassPath(); + public ImmutableList<String> workerClassPathArgs() { + return platform.workerClassPathArgs(); } public ImmutableSet<String> workerProcessArgs() { diff --git a/caliper/src/main/java/com/google/caliper/platform/Platform.java b/caliper/src/main/java/com/google/caliper/platform/Platform.java index 44b6cd2..c5392ce 100644 --- a/caliper/src/main/java/com/google/caliper/platform/Platform.java +++ b/caliper/src/main/java/com/google/caliper/platform/Platform.java @@ -19,6 +19,7 @@ package com.google.caliper.platform; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import java.io.File; @@ -65,7 +66,17 @@ public abstract class Platform { /** * The class path that should be used to run a worker.. */ - public abstract String workerClassPath(); + protected abstract String workerClassPath(); + + /** + * Construct the set of arguments that specify the classpath which + * is passed to the worker. + * + * <p>By default this is just the {@code -cp $workerClassPath}.</p> + */ + public ImmutableList<String> workerClassPathArgs() { + return ImmutableList.of("-cp", workerClassPath()); + } /** * Checks to see whether the specific class is supported on this platform. diff --git a/caliper/src/main/java/com/google/caliper/platform/dalvik/DalvikPlatform.java b/caliper/src/main/java/com/google/caliper/platform/dalvik/DalvikPlatform.java index 3f3e56c..00833f0 100644 --- a/caliper/src/main/java/com/google/caliper/platform/dalvik/DalvikPlatform.java +++ b/caliper/src/main/java/com/google/caliper/platform/dalvik/DalvikPlatform.java @@ -22,6 +22,7 @@ import com.google.caliper.platform.Platform; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.base.Joiner; @@ -83,11 +84,26 @@ public final class DalvikPlatform extends Platform { } @Override - public String workerClassPath() { + protected String workerClassPath() { // TODO(user): Find a way to get the class path programmatically from the class loader. return System.getProperty("java.class.path"); } + /** + * Construct the set of arguments that specify the classpath which + * is passed to the worker. + * + * <p> + * Use {@code -Djava.class.path=$classpath} for dalvik because it is supported + * by dalvikvm and also by app_process (which doesn't recognize "-cp args"). + * </p> + */ + @Override + public ImmutableList<String> workerClassPathArgs() { + String classPathArgs = String.format("-Djava.class.path=%s", workerClassPath()); + return ImmutableList.of(classPathArgs); + } + @Override public Collection<String> inputArguments() { return Collections.emptyList(); diff --git a/caliper/src/main/java/com/google/caliper/runner/WorkerProcess.java b/caliper/src/main/java/com/google/caliper/runner/WorkerProcess.java index 144a21c..d0c0bb5 100644 --- a/caliper/src/main/java/com/google/caliper/runner/WorkerProcess.java +++ b/caliper/src/main/java/com/google/caliper/runner/WorkerProcess.java @@ -201,9 +201,11 @@ import javax.inject.Inject; logger.fine(String.format("Benchmark(%s) %s args: %s", benchmarkClass.name(), platformName, benchmarkJvmOptions)); - String classPath = vmConfig.workerClassPath(); - Collections.addAll(args, "-cp", classPath); - logger.finer(String.format("Class path: %s", classPath)); + ImmutableList<String> classPathArgs = vmConfig.workerClassPathArgs(); + args.addAll(classPathArgs); + logger.finer(String.format("Class path args: %s", classPathArgs)); + + // TODO(iam): consider forwarding -Djava.library.path= for JNI library support. return args; } } |