# HG changeset patch # User Omair Majid # Date 1418258870 18000 # Node ID 37bcf1f12fd883dfd09ef1251ba6066ecd9dce43 # Parent b7cf43343de2cc1aed93f6404c1ee65b471be91b Make the profiler jvm-agent work with Java 6 Reviewed-by: vanaltj Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2014-December/012210.html diff -r b7cf43343de2 -r 37bcf1f12fd8 vm-profiler/jvm-agent/pom.xml --- a/vm-profiler/jvm-agent/pom.xml Wed Dec 10 15:05:03 2014 -0500 +++ b/vm-profiler/jvm-agent/pom.xml Wed Dec 10 19:47:50 2014 -0500 @@ -48,10 +48,13 @@ JVM-side agent for the Thermostat VM Profiler + @@ -66,6 +69,14 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + 1.6 + 1.6 + + diff -r b7cf43343de2 -r 37bcf1f12fd8 vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/InstrumentationControl.java --- a/vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/InstrumentationControl.java Wed Dec 10 15:05:03 2014 -0500 +++ b/vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/InstrumentationControl.java Wed Dec 10 19:47:50 2014 -0500 @@ -125,7 +125,7 @@ private void retransformAlreadyLoadedClasses(Instrumentation instrumentation, ProfilerInstrumentor profiler) { long start = System.nanoTime(); - List> toTransform = new ArrayList<>(); + List> toTransform = new ArrayList>(); for (Class klass : instrumentation.getAllLoadedClasses()) { boolean skipThisClass = false; @@ -171,13 +171,25 @@ try { ResultsFile resultsFile = resultsFileCreator.get(); String path = resultsFile.getPath(); - try (BufferedWriter out = resultsFile.getWriter()) { + BufferedWriter out = null; + try { + out = resultsFile.getWriter(); Map data = recorder.getData(); + System.out.println("AGENT: Writing " + data.size() + " results to: " + path); for (Map.Entry entry : data.entrySet()) { out.write(entry.getValue().get() + "\t" + entry.getKey() + "\n"); } resultsWrittenToDisk = true; lastResults = path; + } finally { + try { + if (out != null) { + out.close(); + } + } catch (IOException e) { + // well, we are screwed + e.printStackTrace(); + } } } catch (IOException e) { e.printStackTrace(); diff -r b7cf43343de2 -r 37bcf1f12fd8 vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/ProfileRecorder.java --- a/vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/ProfileRecorder.java Wed Dec 10 15:05:03 2014 -0500 +++ b/vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/ProfileRecorder.java Wed Dec 10 19:47:50 2014 -0500 @@ -48,7 +48,7 @@ private static final ProfileRecorder profileRecorder = new ProfileRecorder(); /** shared between threads */ - private ConcurrentHashMap profileData = new ConcurrentHashMap<>(); + private ConcurrentHashMap profileData = new ConcurrentHashMap(); // TODO deal with thread id wrap-around @@ -57,10 +57,10 @@ *

* only the thread with the matching thread id is allowed to mutate 'info' */ - private Map threads = new ConcurrentHashMap<>(); + private Map threads = new ConcurrentHashMap(); final static class Info { - public Deque stackFrames = new ArrayDeque<>(); + public Deque stackFrames = new ArrayDeque(); public long timeStamp = Long.MIN_VALUE; } @@ -127,4 +127,4 @@ public Map getData() { return profileData; } -} \ No newline at end of file +} diff -r b7cf43343de2 -r 37bcf1f12fd8 vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/ProfilerAgent.java --- a/vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/ProfilerAgent.java Wed Dec 10 15:05:03 2014 -0500 +++ b/vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/ProfilerAgent.java Wed Dec 10 19:47:50 2014 -0500 @@ -40,6 +40,7 @@ import java.lang.instrument.Instrumentation; import java.lang.reflect.Constructor; import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; import java.util.jar.JarFile; /** @@ -97,7 +98,22 @@ Object main = constructor.newInstance(instrumentation); Method runMethod = klass.getMethod("run"); runMethod.invoke(main); - } catch (ReflectiveOperationException | SecurityException e) { + } catch (ClassNotFoundException e) { + e.printStackTrace(); + System.err.println("Unable to initialize agent"); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + System.err.println("Unable to initialize agent"); + } catch (IllegalAccessException e) { + e.printStackTrace(); + System.err.println("Unable to initialize agent"); + } catch (InstantiationException e) { + e.printStackTrace(); + System.err.println("Unable to initialize agent"); + } catch (InvocationTargetException e) { + e.printStackTrace(); + System.err.println("Unable to initialize agent"); + } catch (SecurityException e) { e.printStackTrace(); System.err.println("Unable to initialize agent"); } diff -r b7cf43343de2 -r 37bcf1f12fd8 vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/ProfilerInstrumentor.java --- a/vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/ProfilerInstrumentor.java Wed Dec 10 15:05:03 2014 -0500 +++ b/vm-profiler/jvm-agent/src/main/java/com/redhat/thermostat/vm/profiler/agent/jvm/ProfilerInstrumentor.java Wed Dec 10 19:47:50 2014 -0500 @@ -45,7 +45,7 @@ public abstract class ProfilerInstrumentor implements ClassFileTransformer { - private static List ignorePackageRegexps = new ArrayList<>(); + private static List ignorePackageRegexps = new ArrayList(); static { // jdk packages diff -r b7cf43343de2 -r 37bcf1f12fd8 vm-profiler/jvm-agent/src/test/java/com/redhat/thermostat/vm/profiler/agent/jvm/InstrumentationControlTest.java --- a/vm-profiler/jvm-agent/src/test/java/com/redhat/thermostat/vm/profiler/agent/jvm/InstrumentationControlTest.java Wed Dec 10 15:05:03 2014 -0500 +++ b/vm-profiler/jvm-agent/src/test/java/com/redhat/thermostat/vm/profiler/agent/jvm/InstrumentationControlTest.java Wed Dec 10 19:47:50 2014 -0500 @@ -133,7 +133,7 @@ public void stopProfilingSavesProfilingResultsToDisk() throws Exception { final String DATA_LOCATION = "foobar"; - Map profileData = new HashMap<>(); + Map profileData = new HashMap(); profileData.put("foo", new AtomicLong(1)); when(recorder.getData()).thenReturn(profileData); @@ -151,7 +151,7 @@ public void vmShutdownSaveDataToDisk() throws Exception { final String DATA_LOCATION = "foobar"; - Map profileData = new HashMap<>(); + Map profileData = new HashMap(); profileData.put("foo", new AtomicLong(1)); when(recorder.getData()).thenReturn(profileData);