1 /* 2 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 24 package vm.mlvm.share.jpda; 25 26 import java.lang.invoke.CallSite; 27 import java.lang.invoke.ConstantCallSite; 28 import java.lang.invoke.MethodHandle; 29 import java.lang.invoke.MethodHandles; 30 import java.lang.invoke.MethodType; 31 import java.util.Arrays; 32 33 import vm.mlvm.share.Env; 34 import vm.mlvm.share.Stratum; 35 36 @Stratum(stratumName="Logo", stratumSourceFileName="INDIFY_SDE_DebuggeeBase.logo") 37 public class INDIFY_SDE_DebuggeeBase extends Debuggee { 38 39 private static MethodType MT_bootstrap() { 40 return MethodType.methodType(Object.class, Object.class, Object.class, Object.class); 41 } 42 43 private static MethodHandle MH_bootstrap() throws NoSuchMethodException, IllegalAccessException { 44 return MethodHandles.lookup().findStatic( 45 INDIFY_SDE_DebuggeeBase.class, "bootstrap", MT_bootstrap()); 46 } 47 48 private static MethodType MT_target() { 49 return MethodType.methodType(void.class, String.class); 50 } 51 52 private static MethodHandle INDY_call; 53 54 private static MethodHandle INDY_call() throws Throwable { 55 if (INDY_call != null) 56 return INDY_call; 57 58 return ((CallSite) MH_bootstrap().invokeWithArguments( 59 MethodHandles.lookup(), "hello", MT_target())).dynamicInvoker(); 60 } 61 62 private static Object bootstrap(Object l, Object n, Object t) throws Throwable { 63 Stratum_Logo_30_BOOTSTRAP: 64 Env.traceNormal("BSM called: " + Arrays.asList(new Object[] { l, n, t })); 65 getDebuggeeInstance().hangUpIfNeeded("bootstrap"); 66 return new ConstantCallSite(MethodHandles.lookup().findStatic( 67 INDIFY_SDE_DebuggeeBase.class, "target", MT_target())); 68 } 69 70 public static void indyWrapper(String s) throws Throwable { 71 Stratum_Logo_20_INDY: 72 INDY_call().invokeExact(s); 73 } 74 75 public static void target(String s) throws Throwable { 76 Debuggee d; 77 Stratum_Logo_40_TARGET: 78 d = getDebuggeeInstance(); 79 if ( d.isWarmingUp() ) 80 Env.traceDebug("Target called. Argument: [" + s + "]"); 81 else 82 Env.traceNormal("Target called. Argument: [" + s + "]"); 83 d.hangUpIfNeeded("target"); 84 } 85 86 public static void stop() throws Throwable { 87 Stratum_Logo_50_END: 88 getDebuggeeInstance().hangUpIfNeeded("stop"); 89 } 90 91 @Override 92 protected void warmUp() throws Throwable { 93 indyWrapper("warming up"); 94 } 95 96 @Override 97 public boolean runDebuggee() throws Throwable { 98 Stratum_Logo_10_BEGIN: 99 indyWrapper("hello from main!"); 100 stop(); 101 return true; 102 } 103 }