Skip to content

Commit 9bb2a56

Browse files
java-team-github-botCaliper Team
authored andcommitted
Internal change
RELNOTES=n/a PiperOrigin-RevId: 830966129
1 parent 25c2ffc commit 9bb2a56

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

caliper-runner/src/main/java/com/google/caliper/runner/target/NonAndroidDeviceHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public boolean apply(String flag) {
6464
// If this is set in the parent VM we do not want it to be inherited by the child
6565
// VM. If it is, the child will die immediately on startup because it will fail to
6666
// bind to the debug port (because the parent VM is already bound to it).
67-
return !flag.startsWith("-agentlib:jdwp");
67+
return !flag.startsWith("-agentlib:jdwp")
68+
;
6869
}
6970
};
7071

caliper/src/test/java/com/google/caliper/runner/config/CaliperConfigTest.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@
2626
import com.google.caliper.runner.options.ParsedOptions;
2727
import com.google.caliper.runner.target.Device;
2828
import com.google.caliper.runner.target.LocalDevice;
29+
import com.google.common.base.Predicate;
30+
import com.google.common.collect.Collections2;
2931
import com.google.common.collect.ImmutableList;
3032
import com.google.common.collect.ImmutableMap;
3133
import com.google.common.collect.ImmutableSet;
3234
import java.io.File;
3335
import java.lang.management.ManagementFactory;
36+
import java.util.Collection;
3437
import org.junit.Rule;
3538
import org.junit.Test;
3639
import org.junit.rules.TemporaryFolder;
@@ -101,6 +104,33 @@ public void testGetDeviceConfig_missingType() {
101104
}
102105
}
103106

107+
/**
108+
* Predicate for filtering out JVM flags (from those used to start the runner JVM) that we don't
109+
* want to pass on to worker VMs.
110+
*/
111+
private static final Predicate<String> JVM_FLAGS_TO_RETAIN =
112+
new Predicate<String>() {
113+
@Override
114+
public boolean apply(String flag) {
115+
// Exclude the -agentlib:jdwp param which configures the socket debugging protocol.
116+
// If this is set in the parent VM we do not want it to be inherited by the child
117+
// VM. If it is, the child will die immediately on startup because it will fail to
118+
// bind to the debug port (because the parent VM is already bound to it).
119+
return !flag.startsWith("-agentlib:jdwp")
120+
;
121+
}
122+
};
123+
124+
/**
125+
* Returns the set of VM args used when starting this process that we want to pass on to worker
126+
* VMs.
127+
*/
128+
private static Collection<String> jvmInputArguments() {
129+
// TODO(cgdecker): Don't pass any input args to workers by default.
130+
return Collections2.filter(
131+
ManagementFactory.getRuntimeMXBean().getInputArguments(), JVM_FLAGS_TO_RETAIN);
132+
}
133+
104134
@Test
105135
public void getDefaultVmConfig() throws Exception {
106136
CaliperConfig configuration =
@@ -113,7 +143,7 @@ public void getDefaultVmConfig() throws Exception {
113143
assertEquals(System.getProperty("java.home"), defaultVmConfig.home().get());
114144
ImmutableList<String> expectedArgs =
115145
new ImmutableList.Builder<String>()
116-
.addAll(ManagementFactory.getRuntimeMXBean().getInputArguments())
146+
.addAll(jvmInputArguments())
117147
.add("-very")
118148
.add("-special=args")
119149
.build();

0 commit comments

Comments
 (0)