5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.hotspot; 24 25 import jdk.vm.ci.code.CompiledCode; 26 import jdk.vm.ci.code.InstalledCode; 27 import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider; 28 import jdk.vm.ci.hotspot.HotSpotVMEventListener; 29 import org.graalvm.compiler.code.CompilationResult; 30 import org.graalvm.compiler.debug.Debug; 31 import org.graalvm.compiler.debug.GraalDebugConfig; 32 import org.graalvm.compiler.serviceprovider.GraalServices; 33 34 import java.util.ArrayList; 35 import java.util.List; 36 37 public class HotSpotGraalVMEventListener implements HotSpotVMEventListener { 38 39 private final HotSpotGraalRuntime runtime; 40 private List<HotSpotCodeCacheListener> listeners; 41 42 HotSpotGraalVMEventListener(HotSpotGraalRuntime runtime) { 43 this.runtime = runtime; 44 listeners = new ArrayList<>(); 45 for (HotSpotCodeCacheListener listener : GraalServices.load(HotSpotCodeCacheListener.class)) { 46 listeners.add(listener); 47 } 48 } 49 50 @Override 51 public void notifyShutdown() { 52 runtime.shutdown(); 53 } 54 55 @Override 56 public void notifyInstall(HotSpotCodeCacheProvider codeCache, InstalledCode installedCode, CompiledCode compiledCode) { 57 if (Debug.isDumpEnabled(Debug.BASIC_LEVEL)) { 58 CompilationResult compResult = Debug.contextLookup(CompilationResult.class); 59 assert compResult != null : "can't dump installed code properly without CompilationResult"; 60 Debug.dump(Debug.BASIC_LEVEL, installedCode, "After code installation"); 61 } 62 if (Debug.isLogEnabled()) { 63 Debug.log("%s", codeCache.disassemble(installedCode)); 64 } 65 for (HotSpotCodeCacheListener listener : listeners) { 66 listener.notifyInstall(codeCache, installedCode, compiledCode); 67 } 68 } 69 70 @Override 71 public void notifyBootstrapFinished() { 72 runtime.notifyBootstrapFinished(); 73 if (GraalDebugConfig.Options.ClearMetricsAfterBootstrap.getValue(runtime.getOptions())) { 74 runtime.clearMeters(); 75 } 76 } 77 } | 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.hotspot; 24 25 import java.util.ArrayList; 26 import java.util.List; 27 28 import org.graalvm.compiler.code.CompilationResult; 29 import org.graalvm.compiler.debug.DebugContext; 30 import org.graalvm.compiler.debug.DebugOptions; 31 import org.graalvm.compiler.serviceprovider.GraalServices; 32 33 import jdk.vm.ci.code.CompiledCode; 34 import jdk.vm.ci.code.InstalledCode; 35 import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider; 36 import jdk.vm.ci.hotspot.HotSpotVMEventListener; 37 38 public class HotSpotGraalVMEventListener implements HotSpotVMEventListener { 39 40 private final HotSpotGraalRuntime runtime; 41 private List<HotSpotCodeCacheListener> listeners; 42 43 HotSpotGraalVMEventListener(HotSpotGraalRuntime runtime) { 44 this.runtime = runtime; 45 listeners = new ArrayList<>(); 46 for (HotSpotCodeCacheListener listener : GraalServices.load(HotSpotCodeCacheListener.class)) { 47 listeners.add(listener); 48 } 49 } 50 51 @Override 52 public void notifyShutdown() { 53 runtime.shutdown(); 54 } 55 56 @Override 57 public void notifyInstall(HotSpotCodeCacheProvider codeCache, InstalledCode installedCode, CompiledCode compiledCode) { 58 DebugContext debug = DebugContext.forCurrentThread(); 59 if (debug.isDumpEnabled(DebugContext.BASIC_LEVEL)) { 60 CompilationResult compResult = debug.contextLookup(CompilationResult.class); 61 assert compResult != null : "can't dump installed code properly without CompilationResult"; 62 debug.dump(DebugContext.BASIC_LEVEL, installedCode, "After code installation"); 63 } 64 if (debug.isLogEnabled()) { 65 debug.log("%s", codeCache.disassemble(installedCode)); 66 } 67 for (HotSpotCodeCacheListener listener : listeners) { 68 listener.notifyInstall(codeCache, installedCode, compiledCode); 69 } 70 } 71 72 @Override 73 public void notifyBootstrapFinished() { 74 runtime.notifyBootstrapFinished(); 75 if (DebugOptions.ClearMetricsAfterBootstrap.getValue(runtime.getOptions())) { 76 runtime.clearMetrics(); 77 } 78 } 79 } |