From 3632df8d96f210577c2d86c0b184737a59db23aa Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Mon, 19 Mar 2012 11:59:49 -0700 Subject: [PATCH] testdir --- tests/indy/one/Asp.java | 6 ++ tests/indy/one/Code1.class | Bin 0 -> 1528 bytes tests/indy/one/Code1.java | 21 +++++++ tests/indy/one/Generator.class | Bin 0 -> 3757 bytes tests/indy/one/Generator.java | 101 +++++++++++++++++++++++++++++++++ tests/indy/one/Invoker.class | Bin 0 -> 388 bytes tests/indy/one/indy.jar | Bin 0 -> 409 bytes tests/indy/two/Asp.java | 6 ++ tests/indy/two/Code1.java | 21 +++++++ tests/indy/two/Generator.java | 101 +++++++++++++++++++++++++++++++++ tests/indy/two/indy.jar | Bin 0 -> 409 bytes 11 files changed, 256 insertions(+) create mode 100644 tests/indy/one/Asp.java create mode 100644 tests/indy/one/Code1.class create mode 100644 tests/indy/one/Code1.java create mode 100644 tests/indy/one/Generator.class create mode 100644 tests/indy/one/Generator.java create mode 100644 tests/indy/one/Invoker.class create mode 100644 tests/indy/one/indy.jar create mode 100644 tests/indy/two/Asp.java create mode 100644 tests/indy/two/Code1.java create mode 100644 tests/indy/two/Generator.java create mode 100644 tests/indy/two/indy.jar diff --git a/tests/indy/one/Asp.java b/tests/indy/one/Asp.java new file mode 100644 index 000000000..a7a41ef7b --- /dev/null +++ b/tests/indy/one/Asp.java @@ -0,0 +1,6 @@ +aspect Aspect { + + before(): staticinitialization(!Aspect) { + System.out.println(thisJoinPointStaticPart); + } +} diff --git a/tests/indy/one/Code1.class b/tests/indy/one/Code1.class new file mode 100644 index 0000000000000000000000000000000000000000..5e5c2ba998d80b1b87ff4cc9310afe9a413081fc GIT binary patch literal 1528 zcmaJ>?NZY~6g^wohK4Fo3R=`s5Tpf4MewV^B32M)Dmqh!8GokfLIY{iNm54M#K%y7 zfTJ@$fDh$(v#B(dVt(vq_nv$1_x}3*{U?A`>`DkRM9Nm3uSf_pj2x?{YQa#=qr$t| zG1pv%=(=v|Zi!(an>%0#dtey@h{X{>lwr7{n|!a`tZ{o^tr?slQL!}DI8bffJ9jR_ zZbNq%q>3=65Z$3=#V~?|gwY!TFM9o!{1S{{#K5_Q(+7BLesF(_V~v6^MMj%%we z1}BKo%~R`y7v6HWVbyn3vuBYz6+Nq3HKQ?UC^#!@FUgO)HLommna!?n3wQ?A>D=cxYmg& zjx2IienW)DkjwUQw{I3?EFv#qiDB;lCOT=0V;Kd8A>UHjP#tQNu^w~cQt^ma;&_Br z%Fdx~)~l}S>KcO@ERc^4q_$Jlz)erQ*Oej|nbetm{oDLXx@ER}A;ABNMSwb9=+sN%Uv{ z>!*$()ND|{1qA)vXPD?6bTZu;_GCa+aIPAis5`J zyts6ZhsDSbtbIsDF7V_tAqIqV3Bm)zw2shu6iFn6jgrrT=O~h#_@H22IG@G~l*nQj xlQfG(!IQ)WUeZmHI5zQ$a#AK8FIbuGHt?EcA#BlI2-|o=yG*i08u}fi{s6m+f^Pr- literal 0 HcmV?d00001 diff --git a/tests/indy/one/Code1.java b/tests/indy/one/Code1.java new file mode 100644 index 000000000..2899340d2 --- /dev/null +++ b/tests/indy/one/Code1.java @@ -0,0 +1,21 @@ +import java.lang.invoke.CallSite; +import java.lang.invoke.ConstantCallSite; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +public class Code1 { + + // Called via invokedynamic from a generated class + private static void foo() { + System.out.println("foo() is running"); + } + + public static CallSite bootstrap(MethodHandles.Lookup caller, String name, MethodType type) throws NoSuchMethodException, IllegalAccessException { + MethodHandles.Lookup lookup = MethodHandles.lookup(); + Class thisClass = lookup.lookupClass(); + MethodHandle mh = lookup.findStatic(thisClass, name, type); + return new ConstantCallSite(mh);//mh.asType(type)); + } + +} \ No newline at end of file diff --git a/tests/indy/one/Generator.class b/tests/indy/one/Generator.class new file mode 100644 index 0000000000000000000000000000000000000000..d4a793b23ccdaa33e3f1eff60186d8d3884e5119 GIT binary patch literal 3757 zcmb_f`FC4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hoV#7# zysrA#g#8q`AyNVCmKc9$;I_nQsF-nwUj_er1AmY?=~4qacRGr}38zxZSaMSp*toXE zACMfSqLe(1DK1$&2mMuG_g%ftU_$32hB+5ACSoo^-T|JvTYfhWmKmNQ1yO zF5ZqU=*3=sZPg305BvGmO)&Q(OvM5Ni104e$JICBi@c5KTNG$@?Gyv|C^d$9_hFEW z!FL|vc$bS`;%pzE{gE0DM54<$7>O<8aAa^9Mda3qKrqsJV7a^`{fBrMT}>^I8NzRipO|;iOu;g$ zOzv?K{Y})EkW)}~iX@wDMj_%omK N-^6S93;u@Q{{ZB)n_U0^ literal 0 HcmV?d00001 diff --git a/tests/indy/one/Generator.java b/tests/indy/one/Generator.java new file mode 100644 index 000000000..77f1e1807 --- /dev/null +++ b/tests/indy/one/Generator.java @@ -0,0 +1,101 @@ + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.lang.invoke.CallSite; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +import org.objectweb.asm.*; + +public class Generator implements Opcodes { + + private String generatedRunnerTypename,linkClassName,dynMethodName,dynMethodDescriptor; + private byte[] bytes; + + /** + * Main entry point generates a default thing, in this case a class called 'Invoker' that will use the bootstrap method on Code1 to run 'foo()' + * @param args + * @throws Throwable + */ + public static void main(String[] args) throws Throwable { + Generator g = new Generator("Invoker","Code1","foo","()V"); + g.dump(); + } + + public byte[] getBytes() { + return bytes; + } + + public Generator(String generatedRunnerTypename, String linkClassName, String dynMethodName, String dynMethodDescriptor) { + this.generatedRunnerTypename = generatedRunnerTypename; + this.linkClassName = linkClassName; + this.dynMethodName = dynMethodName; + this.dynMethodDescriptor = dynMethodDescriptor; + this.bytes = generateClass(); + } + + public void dump() { + try { + FileOutputStream fos + = new FileOutputStream(new File(generatedRunnerTypename+".class")); + fos.write(bytes); + fos.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public byte[] generateClass() { + ClassWriter cw = new ClassWriter(0); + cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, generatedRunnerTypename, null, "java/lang/Object", null); + createConstructor(cw); + createMain(cw); + cw.visitEnd(); + return cw.toByteArray(); + } + + private void createMain(ClassWriter cw) { + MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null); + mv.visitCode(); + MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, + MethodType.class); + Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, this.linkClassName, "bootstrap", + mt.toMethodDescriptorString()); + int maxStackSize = 0;//addMethodParameters(mv); + mv.visitInvokeDynamicInsn(dynMethodName, dynMethodDescriptor, bootstrap); + mv.visitInsn(RETURN); + mv.visitMaxs(maxStackSize, 1); + mv.visitEnd(); + } + +// public byte[] dump(String dynamicInvokerClassName, String dynamicLinkageClassName, String bootstrapMethodName, String targetMethodDescriptor) +// throws Exception { +// ClassWriter cw = new ClassWriter(0); +// cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, dynamicInvokerClassName, null, "java/lang/Object", null); +// createConstructor(cw); +// createMain(dynamicLinkageClassName, bootstrapMethodName, targetMethodDescriptor, cw); +// cw.visitEnd(); +// return cw.toByteArray(); +// } + + + +// protected int addMethodParameters(MethodVisitor mv) { +// return 0; +// } + + + private void createConstructor(ClassWriter cw) { + MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "", "()V", null, null); + mv.visitCode(); + mv.visitVarInsn(ALOAD, 0); + mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "", "()V"); + mv.visitInsn(RETURN); + mv.visitMaxs(1, 1); + mv.visitEnd(); + } +} \ No newline at end of file diff --git a/tests/indy/one/Invoker.class b/tests/indy/one/Invoker.class new file mode 100644 index 0000000000000000000000000000000000000000..6f651583d5396f64f8d31bf836ceb5a7831fed86 GIT binary patch literal 388 zcmZWlyH3L}6g_SmhlW5Oyk;bZge5|ZK@4;OsfeMd3zJJsaU1L?F_ri%CZrC003U_8 zrbPr{OTO|s_i@hs_*}jNIK=^jf29{@E=wPbp*s@`k>o;8lbgv*-di6{27acrvgZuV zC?1FKzyq}4Gqj$B(hU32-SD??WJ{%|X*_1|1}2jyJ~kQJ6Ju;;OHnXXQ7v74k58_p zeKgsn&{;04qoFbL=OV48t-IEcKZUn1g-qlB>_FuCNLiVN*ur*z5SwMqT8NKu6;lE z{@vrxAIToj8fib66Fes+FE8>9)u%H(%VjXFKC7mj6DPspmPrT1dKmc+j4q zpkOkuv@(~}uyw>&!`5q)!}250D>nmthtzy=QlYGF!f{dG~ScVUM1BAEnLWrnCCqduaYPMfR=!2JST#ey8>t zlr`uFc(ZfdU}0Ur%E-Xb0>lB{j7%a7h)_h91BD_gzzEX-Z&o&t5=J1j2huJ;BN-R~ D;7peX literal 0 HcmV?d00001 diff --git a/tests/indy/two/Asp.java b/tests/indy/two/Asp.java new file mode 100644 index 000000000..329822c9d --- /dev/null +++ b/tests/indy/two/Asp.java @@ -0,0 +1,6 @@ +aspect Aspect { + + before(): execution(* *.*(..)) && !within(Aspect) { + System.out.println(thisJoinPointStaticPart); + } +} diff --git a/tests/indy/two/Code1.java b/tests/indy/two/Code1.java new file mode 100644 index 000000000..2899340d2 --- /dev/null +++ b/tests/indy/two/Code1.java @@ -0,0 +1,21 @@ +import java.lang.invoke.CallSite; +import java.lang.invoke.ConstantCallSite; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +public class Code1 { + + // Called via invokedynamic from a generated class + private static void foo() { + System.out.println("foo() is running"); + } + + public static CallSite bootstrap(MethodHandles.Lookup caller, String name, MethodType type) throws NoSuchMethodException, IllegalAccessException { + MethodHandles.Lookup lookup = MethodHandles.lookup(); + Class thisClass = lookup.lookupClass(); + MethodHandle mh = lookup.findStatic(thisClass, name, type); + return new ConstantCallSite(mh);//mh.asType(type)); + } + +} \ No newline at end of file diff --git a/tests/indy/two/Generator.java b/tests/indy/two/Generator.java new file mode 100644 index 000000000..77f1e1807 --- /dev/null +++ b/tests/indy/two/Generator.java @@ -0,0 +1,101 @@ + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.lang.invoke.CallSite; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +import org.objectweb.asm.*; + +public class Generator implements Opcodes { + + private String generatedRunnerTypename,linkClassName,dynMethodName,dynMethodDescriptor; + private byte[] bytes; + + /** + * Main entry point generates a default thing, in this case a class called 'Invoker' that will use the bootstrap method on Code1 to run 'foo()' + * @param args + * @throws Throwable + */ + public static void main(String[] args) throws Throwable { + Generator g = new Generator("Invoker","Code1","foo","()V"); + g.dump(); + } + + public byte[] getBytes() { + return bytes; + } + + public Generator(String generatedRunnerTypename, String linkClassName, String dynMethodName, String dynMethodDescriptor) { + this.generatedRunnerTypename = generatedRunnerTypename; + this.linkClassName = linkClassName; + this.dynMethodName = dynMethodName; + this.dynMethodDescriptor = dynMethodDescriptor; + this.bytes = generateClass(); + } + + public void dump() { + try { + FileOutputStream fos + = new FileOutputStream(new File(generatedRunnerTypename+".class")); + fos.write(bytes); + fos.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public byte[] generateClass() { + ClassWriter cw = new ClassWriter(0); + cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, generatedRunnerTypename, null, "java/lang/Object", null); + createConstructor(cw); + createMain(cw); + cw.visitEnd(); + return cw.toByteArray(); + } + + private void createMain(ClassWriter cw) { + MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null); + mv.visitCode(); + MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, + MethodType.class); + Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, this.linkClassName, "bootstrap", + mt.toMethodDescriptorString()); + int maxStackSize = 0;//addMethodParameters(mv); + mv.visitInvokeDynamicInsn(dynMethodName, dynMethodDescriptor, bootstrap); + mv.visitInsn(RETURN); + mv.visitMaxs(maxStackSize, 1); + mv.visitEnd(); + } + +// public byte[] dump(String dynamicInvokerClassName, String dynamicLinkageClassName, String bootstrapMethodName, String targetMethodDescriptor) +// throws Exception { +// ClassWriter cw = new ClassWriter(0); +// cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, dynamicInvokerClassName, null, "java/lang/Object", null); +// createConstructor(cw); +// createMain(dynamicLinkageClassName, bootstrapMethodName, targetMethodDescriptor, cw); +// cw.visitEnd(); +// return cw.toByteArray(); +// } + + + +// protected int addMethodParameters(MethodVisitor mv) { +// return 0; +// } + + + private void createConstructor(ClassWriter cw) { + MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "", "()V", null, null); + mv.visitCode(); + mv.visitVarInsn(ALOAD, 0); + mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "", "()V"); + mv.visitInsn(RETURN); + mv.visitMaxs(1, 1); + mv.visitEnd(); + } +} \ No newline at end of file diff --git a/tests/indy/two/indy.jar b/tests/indy/two/indy.jar new file mode 100644 index 0000000000000000000000000000000000000000..d6ec561f4a09536fc7aef1a9a991f10818efee70 GIT binary patch literal 409 zcmWIWW@Zs#;Nak3P)jLrU_b)A3@i+ud1d+8sYQCpIf=!^|4uP5lm^)PA2tx#bKQ)S zx3TVnsj{Jpj$jf`(gJP|S02~c88Jy+w-elZR~|W^wMqT8NKu6;lE z{@vrxAIToj8fib66Fes+FE8>9)u%H(%VjXFKC7mj6DPspmPrT1dKmc+j4q zpkOkuv@(~}uyw>&!`5q)!}250D>nmthtzy=QlYGF!f{dG~ScVUM1BAEnLWrnCCqduaYPMfR=!2JST#ey8>t zlr`uFc(ZfdU}0Ur%E-Xb0>lB{j7%a7h)_h91BD_gzzEX-Z&o&t5=J1j2huJ;BN-R~ D;7peX literal 0 HcmV?d00001 -- 2.39.5