2626import com .google .caliper .runner .options .ParsedOptions ;
2727import com .google .caliper .runner .target .Device ;
2828import com .google .caliper .runner .target .LocalDevice ;
29+ import com .google .common .base .Predicate ;
30+ import com .google .common .collect .Collections2 ;
2931import com .google .common .collect .ImmutableList ;
3032import com .google .common .collect .ImmutableMap ;
3133import com .google .common .collect .ImmutableSet ;
3234import java .io .File ;
3335import java .lang .management .ManagementFactory ;
36+ import java .util .Collection ;
3437import org .junit .Rule ;
3538import org .junit .Test ;
3639import 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