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 jdk.vm.ci.hotspot; 24 25 import java.lang.reflect.Field; 26 27 import jdk.vm.ci.code.BailoutException; 28 import jdk.vm.ci.code.BytecodeFrame; 29 import jdk.vm.ci.code.CodeCacheProvider; 30 import jdk.vm.ci.code.CompiledCode; 31 import jdk.vm.ci.code.InstalledCode; 32 import jdk.vm.ci.code.RegisterConfig; 33 import jdk.vm.ci.code.TargetDescription; 34 import jdk.vm.ci.code.site.Call; 35 import jdk.vm.ci.code.site.Mark; 36 import jdk.vm.ci.meta.ResolvedJavaMethod; 37 import jdk.vm.ci.meta.SpeculationLog; 38 39 /** 40 * HotSpot implementation of {@link CodeCacheProvider}. 41 */ 42 public class HotSpotCodeCacheProvider implements CodeCacheProvider { 43 44 protected final HotSpotJVMCIRuntimeProvider runtime; 45 protected final HotSpotVMConfig config; 46 protected final TargetDescription target; 47 protected final RegisterConfig regConfig; 48 49 public HotSpotCodeCacheProvider(HotSpotJVMCIRuntimeProvider runtime, HotSpotVMConfig config, TargetDescription target, RegisterConfig regConfig) { 50 this.runtime = runtime; 51 this.config = config; 52 this.target = target; 53 this.regConfig = regConfig; 54 } 55 56 @Override 57 public String getMarkName(Mark mark) { 58 int markId = (int) mark.id; 59 Field[] fields = runtime.getConfig().getClass().getDeclaredFields(); 60 for (Field f : fields) { 61 if (f.getName().startsWith("MARKID_")) { 62 f.setAccessible(true); 63 try { 64 if (f.getInt(runtime.getConfig()) == markId) { 65 return f.getName(); 66 } 67 } catch (Exception e) { 68 } 69 } 70 } 71 return CodeCacheProvider.super.getMarkName(mark); 72 } 73 74 /** 75 * Decodes a call target to a mnemonic if possible. 76 */ 77 @Override 78 public String getTargetName(Call call) { 79 Field[] fields = runtime.getConfig().getClass().getDeclaredFields(); 80 for (Field f : fields) { 81 if (f.getName().endsWith("Stub")) { 82 f.setAccessible(true); 83 Object address; 84 try { 85 address = f.get(runtime.getConfig()); 86 if (address.equals(call.target)) { 87 return f.getName() + ":0x" + Long.toHexString((Long) address); 88 } 89 } catch (IllegalArgumentException | IllegalAccessException e) { 90 } 91 } 92 } 93 return CodeCacheProvider.super.getTargetName(call); 94 } 95 96 @Override 97 public RegisterConfig getRegisterConfig() { 98 return regConfig; 99 } 100 101 @Override 102 public int getMinimumOutgoingSize() { 103 return runtime.getConfig().runtimeCallStackSize; 104 } 105 106 private InstalledCode logOrDump(InstalledCode installedCode, CompiledCode compiledCode) { 107 ((HotSpotJVMCIRuntime) runtime).notifyInstall(this, installedCode, compiledCode); 108 return installedCode; 109 } | 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 jdk.vm.ci.hotspot; 24 25 import java.util.Map; 26 27 import jdk.vm.ci.code.BailoutException; 28 import jdk.vm.ci.code.BytecodeFrame; 29 import jdk.vm.ci.code.CodeCacheProvider; 30 import jdk.vm.ci.code.CompiledCode; 31 import jdk.vm.ci.code.InstalledCode; 32 import jdk.vm.ci.code.RegisterConfig; 33 import jdk.vm.ci.code.TargetDescription; 34 import jdk.vm.ci.code.site.Call; 35 import jdk.vm.ci.code.site.Mark; 36 import jdk.vm.ci.meta.ResolvedJavaMethod; 37 import jdk.vm.ci.meta.SpeculationLog; 38 39 /** 40 * HotSpot implementation of {@link CodeCacheProvider}. 41 */ 42 public class HotSpotCodeCacheProvider implements CodeCacheProvider { 43 44 protected final HotSpotJVMCIRuntimeProvider runtime; 45 protected final HotSpotVMConfig config; 46 protected final TargetDescription target; 47 protected final RegisterConfig regConfig; 48 49 public HotSpotCodeCacheProvider(HotSpotJVMCIRuntimeProvider runtime, HotSpotVMConfig config, TargetDescription target, RegisterConfig regConfig) { 50 this.runtime = runtime; 51 this.config = config; 52 this.target = target; 53 this.regConfig = regConfig; 54 } 55 56 @Override 57 public String getMarkName(Mark mark) { 58 int markId = (int) mark.id; 59 HotSpotVMConfigStore store = runtime.getConfigStore(); 60 for (Map.Entry<String, Long> e : store.getConstants().entrySet()) { 61 String name = e.getKey(); 62 if (name.startsWith("MARKID_") && e.getValue() == markId) { 63 return name; 64 } 65 } 66 return CodeCacheProvider.super.getMarkName(mark); 67 } 68 69 /** 70 * Decodes a call target to a mnemonic if possible. 71 */ 72 @Override 73 public String getTargetName(Call call) { 74 if (call.target instanceof HotSpotForeignCallTarget) { 75 long address = ((HotSpotForeignCallTarget) call.target).address; 76 HotSpotVMConfigStore store = runtime.getConfigStore(); 77 for (Map.Entry<String, VMField> e : store.getFields().entrySet()) { 78 VMField field = e.getValue(); 79 if (field.isStatic() && field.value == address) { 80 return e.getValue() + ":0x" + Long.toHexString(address); 81 } 82 } 83 } 84 return CodeCacheProvider.super.getTargetName(call); 85 } 86 87 @Override 88 public RegisterConfig getRegisterConfig() { 89 return regConfig; 90 } 91 92 @Override 93 public int getMinimumOutgoingSize() { 94 return runtime.getConfig().runtimeCallStackSize; 95 } 96 97 private InstalledCode logOrDump(InstalledCode installedCode, CompiledCode compiledCode) { 98 ((HotSpotJVMCIRuntime) runtime).notifyInstall(this, installedCode, compiledCode); 99 return installedCode; 100 } |