AllocationInstrument extends Instrument { @Override public ImmutableSet<String> getExtraCommandLineArgs(VmConfig vmConfig) { String agentJar = options.get(ALLOCATION_AGENT_JAR_OPTION); if (Strings.isNullOrEmpty(agentJar)) { try { Optional<File> instrumentJar = findAllocationInstrumentJarOnClasspath(); if (instrumentJar.isPresent()) { agentJar = instrumentJar.get().getAbsolutePath(); } } catch (IOException e) { logger.log( SEVERE, "An exception occurred trying to locate the allocation agent jar on the classpath", e); } } if (Strings.isNullOrEmpty(agentJar) || !new File(agentJar).exists()) { throw new IllegalStateException("Can't find required allocationinstrumenter agent jar"); } return new ImmutableSet.Builder<String>() .add("-Xint") .add("-javaagent:" + agentJar) .add("-Xbootclasspath/a:" + agentJar) .build(); }  @Override boolean isBenchmarkMethod(MethodModel method); @Override InstrumentedMethod createInstrumentedMethod(MethodModel benchmarkMethod); @Override boolean parallelizable(); @Override ImmutableSet<String> instrumentOptions(); @Override ImmutableSet<String> getExtraCommandLineArgs(VmConfig vmConfig);  }
@Test public void getExtraCommandLineArgs() throws Exception { AllocationInstrument instrument = new AllocationInstrument(); File fakeJar = File.createTempFile("fake", "jar"); fakeJar.deleteOnExit(); instrument.setOptions(ImmutableMap.of("allocationAgentJar", fakeJar.getAbsolutePath())); ImmutableSet<String> expected = ImmutableSet.of( "-Xint", "-javaagent:" + fakeJar.getAbsolutePath(), "-Xbootclasspath/a:" + fakeJar.getAbsolutePath()); VmConfig vmConfig = VmConfig.builder() .name("foo") .type(VmType.JVM) .home(System.getProperty("java.home")) .build(); assertEquals(expected, instrument.getExtraCommandLineArgs(vmConfig)); fakeJar.delete(); }