New upstream version 1.9.0
Emmanuel Bourg
5 years ago
760 | 760 | iList.append(new InstructionCP(Instruction.LDC_W, classIndex)); |
761 | 761 | } |
762 | 762 | } else { |
763 | className = className.replace('/', '.'); | |
763 | 764 | iList.append(InstructionFactory.PUSH(cp, className)); |
764 | 765 | iList.append(this.createInvoke("java.lang.Class", "forName", ObjectType.CLASS, Type.STRINGARRAY1, |
765 | 766 | Constants.INVOKESTATIC)); |
88 | 88 | public static final BasicType CHAR = new BasicType(Constants.T_CHAR); |
89 | 89 | public static final ObjectType OBJECT = new ObjectType("java.lang.Object"); |
90 | 90 | public static final ObjectType STRING = new ObjectType("java.lang.String"); |
91 | public static final ObjectType OBJECT_ARRAY = new ObjectType("java.lang.Object[]"); | |
92 | public static final ObjectType STRING_ARRAY = new ObjectType("java.lang.String[]"); | |
91 | public static final ArrayType OBJECT_ARRAY = new ArrayType("java.lang.Object",1); | |
92 | public static final ArrayType STRING_ARRAY = new ArrayType("java.lang.String",1); | |
93 | public static final ArrayType CLASS_ARRAY = new ArrayType("java.lang.Class",1); | |
93 | 94 | public static final ObjectType STRINGBUFFER = new ObjectType("java.lang.StringBuffer"); |
94 | 95 | public static final ObjectType STRINGBUILDER = new ObjectType("java.lang.StringBuilder"); |
95 | 96 | public static final ObjectType THROWABLE = new ObjectType("java.lang.Throwable"); |
128 | 129 | commonTypes.put(CLASS.getSignature(), CLASS); |
129 | 130 | commonTypes.put(OBJECT.getSignature(), OBJECT); |
130 | 131 | commonTypes.put(STRING_ARRAY.getSignature(), STRING_ARRAY); |
132 | commonTypes.put(CLASS_ARRAY.getSignature(), CLASS_ARRAY); | |
131 | 133 | commonTypes.put(OBJECT_ARRAY.getSignature(), OBJECT_ARRAY); |
132 | 134 | commonTypes.put(INTEGER.getSignature(), INTEGER); |
133 | 135 | commonTypes.put(EXCEPTION.getSignature(), EXCEPTION); |
0 | cp ../aj-build/dist/tools/lib/aspectjrt.jar ../lib/test/aspectjrt.jar | |
1 | cp ../aj-build/dist/tools/lib/aspectjrt.jar ../lib/aspectj/lib/aspectjrt.jar | |
2 | cp ../aj-build/dist/tools/lib/aspectjrt.jar ../build/products/tools/dist/lib/aspectjrt.jar |
0 | 0 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> |
1 | 1 | <html> <head> |
2 | <title>AspectJ 1.9.0.RC4 Readme</title> | |
2 | <title>AspectJ 1.9.0 Readme</title> | |
3 | 3 | <style type="text/css"> |
4 | 4 | <!-- |
5 | 5 | P { margin-left: 20px; } |
18 | 18 | </small></div> |
19 | 19 | <p>The full list of resolved issues in 1.9.0 is available |
20 | 20 | <a href="https://bugs.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED&f0=OP&f1=OP&f3=CP&f4=CP&j1=OR&list_id=16866879&product=AspectJ&query_format=advanced&target_milestone=1.9.0">here</a></h2>.</p> |
21 | ||
22 | <h1>AspectJ 1.9.0</h1> | |
23 | ||
24 | <h4>Improved runtime interface</h4> | |
25 | <p>New factory methods have been added to the AspectJ runtime. This is an attempt to more optimally create <tt>thisJoinPoint</tt> and | |
26 | <tt>thisEnclosingJoinPoint</tt> objects. The generated code that invokes these now also uses the ability | |
27 | for the LDC bytecode instruction to load class constants directly (this replaces what was happening | |
28 | previously where generated code referenced string classnames and classloading was being done from the | |
29 | aspectj runtime as the woven application was starting).</p> | |
30 | ||
31 | <p>This is turned on by using <tt>-Xajruntimetarget:1.9</tt>. This option was used previously to enable | |
32 | users to target an old runtime if they knew that old runtime is all that was available at some deployed target. | |
33 | The new generation mechanism is not the default, not until it has had a bit more testing out in the wild.</p> | |
34 | ||
35 | <p>The changes to generated code have a couple of potential side effects: | |
36 | <ul> | |
37 | <li><b>overall size</b>: the woven code may be smaller due to the use of smaller string constant pieces in the generated | |
38 | code (previously strings were smashed together in the generated code and then taken apart by AspectJ at runtime). | |
39 | Since the pieces are smaller, they can be shared across other uses in the class file. | |
40 | <li><b>method size</b>: although the overall class may be smaller there are more instructions involved in preparing the | |
41 | data for invocation of the new joinpoint factory methods. It is possible if you have a lot of joinpoints that we might | |
42 | blow the 64k instruction limit for the <tt>ajc$preClinit</tt> method (where the factory invocation code is generated). | |
43 | Please provide feedback if this happens to you! | |
44 | </ul> | |
45 | ||
46 | <p>In anticipation of not all build plugins supporting that <tt>-Xajruntimetarget</tt> option, you can now specify | |
47 | these kinds of option in the <tt>ASPECTJ_OPTS</tt> environment variable. Set that in your environment:</p> | |
48 | <pre><code> | |
49 | export ASPECTJ_OPTS="-Xajruntimetarget:1.9" | |
50 | </code></pre> | |
51 | <p>And it should get picked up by AspectJ when it runs.</p> | |
52 | ||
53 | <ul> | |
54 | <li>1.9.0 available 2-Apr-2018 | |
55 | </ul> | |
21 | 56 | |
22 | 57 | <h1>AspectJ 1.9.0.RC4</h1> |
23 | 58 | |
281 | 316 | <li><p>Module aware variants of AspectJ paths: <tt>--module-inpath</tt>, <tt>--module-aspectpath</tt>. (<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=526243">Issue 526243</a>)</p> |
282 | 317 | </ul> |
283 | 318 | |
319 | <br><br> | |
320 | ||
321 | ||
284 | 322 | <!-- ============================== --> |
285 | 323 | </body> |
286 | 324 | </html> |
65 | 65 | /** |
66 | 66 | * Initialization |
67 | 67 | */ |
68 | @Override | |
68 | 69 | public void initialize() { |
69 | 70 | |
70 | 71 | } |
79 | 80 | * @param loader |
80 | 81 | * @return woven bytes |
81 | 82 | */ |
83 | @Override | |
82 | 84 | public byte[] preProcess(String className, byte[] bytes, ClassLoader loader, ProtectionDomain protectionDomain) { |
83 | 85 | // TODO AV needs to doc that |
84 | 86 | if (loader == null || className == null || loader.getClass().getName().equals(deleLoader)) { |
170 | 172 | return instance; |
171 | 173 | } |
172 | 174 | |
175 | @Override | |
173 | 176 | public boolean equals(Object obj) { |
174 | 177 | if (!(obj instanceof AdaptorKey)) { |
175 | 178 | return false; |
180 | 183 | && loaderClass.equals(other.loaderClass); |
181 | 184 | } |
182 | 185 | |
186 | @Override | |
183 | 187 | public int hashCode() { |
184 | 188 | return hashValue; |
185 | 189 | } |
300 | 304 | if (loader.equals(myClassLoader)){ |
301 | 305 | adaptor = myClassLoaderAdaptor; |
302 | 306 | } else { |
303 | adaptor = (ExplicitlyInitializedClassLoaderWeavingAdaptor) weavingAdaptors.get(adaptorKey); | |
307 | adaptor = weavingAdaptors.get(adaptorKey); | |
304 | 308 | } |
305 | 309 | if (adaptor == null) { |
306 | 310 | // create it and put it back in the weavingAdaptors map but avoid any kind of instantiation |
369 | 373 | ((ClassLoaderWeavingAdaptor) WeaverContainer.getWeaver(loader, weavingContext)).flushGeneratedClasses(); |
370 | 374 | } |
371 | 375 | |
376 | @Override | |
377 | public void prepareForRedefinition(ClassLoader loader, String className) { | |
378 | ((ClassLoaderWeavingAdaptor) WeaverContainer.getWeaver(loader, weavingContext)).flushGeneratedClassesFor(className); | |
379 | } | |
380 | ||
372 | 381 | }⏎ |
11 | 11 | import java.io.IOException; |
12 | 12 | import java.io.InputStream; |
13 | 13 | import java.lang.reflect.Field; |
14 | import java.lang.reflect.InvocationTargetException; | |
15 | import java.lang.reflect.Method; | |
16 | 14 | import java.net.MalformedURLException; |
17 | 15 | import java.net.URL; |
18 | 16 | import java.security.ProtectionDomain; |
23 | 21 | import java.util.Iterator; |
24 | 22 | import java.util.LinkedList; |
25 | 23 | import java.util.List; |
24 | import java.util.Map; | |
25 | import java.util.Map.Entry; | |
26 | 26 | import java.util.Properties; |
27 | 27 | import java.util.Set; |
28 | 28 | import java.util.StringTokenizer; |
113 | 113 | * |
114 | 114 | * @deprecated |
115 | 115 | */ |
116 | @Deprecated | |
116 | 117 | public ClassLoaderWeavingAdaptor(final ClassLoader deprecatedLoader, final IWeavingContext deprecatedContext) { |
117 | 118 | super(); |
118 | 119 | if (trace.isTraceEnabled()) { |
134 | 135 | * Callback when we need to define a Closure in the JVM |
135 | 136 | * |
136 | 137 | */ |
138 | @Override | |
137 | 139 | public void acceptClass (String name, byte[] originalBytes, byte[] wovenBytes) { |
138 | 140 | try { |
139 | 141 | if (shouldDump(name.replace('/', '.'), false)) { |
1005 | 1007 | generatedClasses = new HashMap<String, IUnwovenClassFile>(); |
1006 | 1008 | } |
1007 | 1009 | |
1010 | /** | |
1011 | * Remove generated classes based on the supplied className. This will | |
1012 | * remove any entries related to this name - so the class itself plus | |
1013 | * and inner classes. | |
1014 | * @param className a slashed classname (e.g. com/foo/Bar) | |
1015 | */ | |
1016 | public void flushGeneratedClassesFor(String className) { | |
1017 | try { | |
1018 | String dottedClassName = className.replace('/', '.'); | |
1019 | String dottedClassNameDollar = dottedClassName+"$"; // to pickup inner classes | |
1020 | Iterator<Map.Entry<String, IUnwovenClassFile>> iter = generatedClasses.entrySet().iterator(); | |
1021 | while (iter.hasNext()) { | |
1022 | Entry<String, IUnwovenClassFile> next = iter.next(); | |
1023 | String existingGeneratedName = next.getKey(); | |
1024 | if (existingGeneratedName.equals(dottedClassName) || | |
1025 | existingGeneratedName.startsWith(dottedClassNameDollar)) { | |
1026 | iter.remove(); | |
1027 | } | |
1028 | } | |
1029 | } catch (Throwable t) { | |
1030 | new RuntimeException("Unexpected problem tidying up generated classes for "+className,t).printStackTrace(); | |
1031 | } | |
1032 | } | |
1033 | ||
1008 | 1034 | private Unsafe unsafe; |
1009 | 1035 | |
1010 | 1036 | private Unsafe getUnsafe() throws NoSuchFieldException, IllegalAccessException { |
1060 | 1086 | trace.exit("defineClass", clazz); |
1061 | 1087 | } |
1062 | 1088 | } |
1089 | ||
1063 | 1090 | }⏎ |
0 | 0 | /******************************************************************************* |
1 | * Copyright (c) 2005 Contributors. | |
1 | * Copyright (c) 2005,2018 Contributors. | |
2 | 2 | * All rights reserved. |
3 | 3 | * This program and the accompanying materials are made available |
4 | 4 | * under the terms of the Eclipse Public License v1.0 |
5 | 5 | * which accompanies this distribution and is available at |
6 | 6 | * http://eclipse.org/legal/epl-v10.html |
7 | * | |
8 | * Contributors: | |
9 | * Alexandre Vasseur initial implementation | |
10 | 7 | *******************************************************************************/ |
11 | 8 | package org.aspectj.weaver.loadtime; |
12 | 9 | |
17 | 14 | * further use on Java 1.3 / 1.4 |
18 | 15 | * |
19 | 16 | * @author Alexandre Vasseur |
17 | * @author Andy Clement | |
20 | 18 | */ |
21 | 19 | public interface ClassPreProcessor { |
22 | 20 | |
25 | 23 | */ |
26 | 24 | void initialize(); |
27 | 25 | |
28 | /** | |
29 | * Weave | |
30 | * | |
31 | * @param className | |
32 | * @param bytes | |
33 | * @param classLoader | |
34 | * @param a protection domain that may be used for defining extraneous classes generated as part of modifying the one passed in | |
35 | * @return | |
36 | */ | |
37 | 26 | byte[] preProcess(String className, byte[] bytes, ClassLoader classLoader, ProtectionDomain protectionDomain); |
27 | ||
28 | void prepareForRedefinition(ClassLoader loader, String className); | |
38 | 29 | }⏎ |
0 | 0 | /******************************************************************************* |
1 | * Copyright (c) 2005 Contributors. | |
1 | * Copyright (c) 2005,2018 Contributors. | |
2 | 2 | * All rights reserved. |
3 | 3 | * This program and the accompanying materials are made available |
4 | 4 | * under the terms of the Eclipse Public License v1.0 |
5 | 5 | * which accompanies this distribution and is available at |
6 | 6 | * http://eclipse.org/legal/epl-v10.html |
7 | * | |
8 | * Contributors: | |
9 | * Alexandre Vasseur initial implementation | |
10 | 7 | *******************************************************************************/ |
11 | 8 | package org.aspectj.weaver.loadtime; |
12 | 9 | |
17 | 14 | /** |
18 | 15 | * Java 1.5 adapter for class pre processor |
19 | 16 | * |
20 | * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a> | |
17 | * @author Alexandre Vasseur | |
18 | * @author Andy Clement | |
21 | 19 | */ |
22 | 20 | public class ClassPreProcessorAgentAdapter implements ClassFileTransformer { |
23 | 21 | |
24 | /** | |
25 | * Concrete preprocessor. | |
26 | */ | |
27 | private static ClassPreProcessor s_preProcessor; | |
22 | private static ClassPreProcessor classPreProcessor; | |
28 | 23 | |
29 | 24 | static { |
30 | 25 | try { |
31 | s_preProcessor = new Aj(); | |
32 | s_preProcessor.initialize(); | |
26 | classPreProcessor = new Aj(); | |
27 | classPreProcessor.initialize(); | |
33 | 28 | } catch (Exception e) { |
34 | 29 | throw new ExceptionInInitializerError("could not initialize JSR163 preprocessor due to: " + e.toString()); |
35 | 30 | } |
45 | 40 | * @param bytes the incoming bytes (before weaving) |
46 | 41 | * @return the woven bytes |
47 | 42 | */ |
43 | @Override | |
48 | 44 | public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, |
49 | 45 | byte[] bytes) throws IllegalClassFormatException { |
50 | 46 | if (classBeingRedefined != null) { |
51 | 47 | System.err.println("INFO: (Enh120375): AspectJ attempting reweave of '" + className + "'"); |
48 | classPreProcessor.prepareForRedefinition(loader, className); | |
52 | 49 | } |
53 | return s_preProcessor.preProcess(className, bytes, loader, protectionDomain); | |
50 | return classPreProcessor.preProcess(className, bytes, loader, protectionDomain); | |
54 | 51 | } |
55 | 52 | } |
806 | 806 | buildConfig.setTargetAspectjRuntimeLevel(Constants.RUNTIME_LEVEL_12); |
807 | 807 | } else if (arg.endsWith(":1.5")) { |
808 | 808 | buildConfig.setTargetAspectjRuntimeLevel(Constants.RUNTIME_LEVEL_15); |
809 | } else { | |
810 | showError("-Xajruntimetarget:<level> only supports a target level of 1.2 or 1.5"); | |
809 | } else if (arg.endsWith(":1.9")) { | |
810 | buildConfig.setTargetAspectjRuntimeLevel(Constants.RUNTIME_LEVEL_19); | |
811 | } else { | |
812 | showError("-Xajruntimetarget:<level> supports a target level of 1.2, 1.5, 1.9"); | |
811 | 813 | } |
812 | 814 | } else if (arg.equals("-timers")) { |
813 | 815 | buildConfig.setTiming(true); |
20 | 20 | import java.util.ArrayList; |
21 | 21 | import java.util.LinkedList; |
22 | 22 | import java.util.List; |
23 | import java.util.StringTokenizer; | |
23 | 24 | |
24 | 25 | public class ConfigParser { |
25 | 26 | Location location; |
42 | 43 | LinkedList<Arg> args = new LinkedList<Arg>(); |
43 | 44 | for (int i = 0; i < argsArray.length; i++) { |
44 | 45 | args.add(new Arg(argsArray[i], location)); |
46 | } | |
47 | String aspectjOptions = null; | |
48 | try { | |
49 | aspectjOptions = System.getenv("ASPECTJ_OPTS"); | |
50 | if (aspectjOptions == null) { | |
51 | aspectjOptions = System.getProperty("ASPECTJ_OPTS"); | |
52 | } | |
53 | } catch (Throwable t) { | |
54 | aspectjOptions = null; | |
55 | } | |
56 | if (aspectjOptions != null) { | |
57 | StringTokenizer st = new StringTokenizer(aspectjOptions); | |
58 | while (st.hasMoreElements()) { | |
59 | args.add(new Arg(st.nextToken(),location)); | |
60 | } | |
45 | 61 | } |
46 | 62 | parseArgs(args); |
47 | 63 | } |
137 | 153 | if (sourceFile.getName().charAt(0) == '*') { |
138 | 154 | if (sourceFile.getName().equals("*.java")) { |
139 | 155 | addFiles(sourceFile.getParentFile(), new FileFilter() { |
156 | @Override | |
140 | 157 | public boolean accept(File f) { |
141 | 158 | return f != null && f.getName().endsWith(".java"); |
142 | 159 | } |
143 | 160 | }); |
144 | 161 | } else if (sourceFile.getName().equals("*.aj")) { |
145 | 162 | addFiles(sourceFile.getParentFile(), new FileFilter() { |
163 | @Override | |
146 | 164 | public boolean accept(File f) { |
147 | 165 | return f != null && f.getName().endsWith(".aj"); |
148 | 166 | } |
286 | 304 | private Location location; |
287 | 305 | private String value; |
288 | 306 | |
307 | @Override | |
289 | 308 | public String toString() { |
290 | 309 | return "Arg[location="+location+" value="+value+"]"; |
291 | 310 | } |
319 | 338 | |
320 | 339 | public abstract int getLine(); |
321 | 340 | |
341 | @Override | |
322 | 342 | public abstract String toString(); |
323 | 343 | } |
324 | 344 | |
331 | 351 | this.file = file; |
332 | 352 | } |
333 | 353 | |
354 | @Override | |
334 | 355 | public File getFile() { |
335 | 356 | return file; |
336 | 357 | } |
337 | 358 | |
359 | @Override | |
338 | 360 | public File getDirectory() { |
339 | 361 | return file.getParentFile(); |
340 | 362 | } |
341 | 363 | |
364 | @Override | |
342 | 365 | public int getLine() { |
343 | 366 | return line; |
344 | 367 | } |
345 | 368 | |
369 | @Override | |
346 | 370 | public String toString() { |
347 | 371 | return file.getPath() + ":" + line; |
348 | 372 | } |
349 | 373 | } |
350 | 374 | |
351 | 375 | static class CommandLineLocation extends Location { |
376 | @Override | |
352 | 377 | public File getFile() { |
353 | 378 | return new File(System.getProperty("user.dir")); |
354 | 379 | } |
355 | 380 | |
381 | @Override | |
356 | 382 | public File getDirectory() { |
357 | 383 | return new File(System.getProperty("user.dir")); |
358 | 384 | } |
359 | 385 | |
386 | @Override | |
360 | 387 | public int getLine() { |
361 | 388 | return -1; |
362 | 389 | } |
363 | 390 | |
391 | @Override | |
364 | 392 | public String toString() { |
365 | 393 | return "command-line"; |
366 | 394 | } |
3 | 3 | The -Xlintfile:lint.properties allows fine-grained control. In tools.jar, see |
4 | 4 | org/aspectj/weaver/XlintDefault.properties for the default behavior and a template to copy. |
5 | 5 | ### AspectJ-specific messages |
6 | compiler.name = AspectJ Compiler 1.9.0.RC3 | |
6 | compiler.name = AspectJ Compiler 1.9.0 | |
7 | 7 | compiler.version = Eclipse Compiler #1bfc7b4202e874c(Feb2018), 3.14 |
8 | 8 | compiler.copyright = |
9 | 9 |
21 | 21 | |
22 | 22 | public final static String RUNTIME_LEVEL_12 = "1.2"; |
23 | 23 | public final static String RUNTIME_LEVEL_15 = "1.5"; |
24 | public final static String RUNTIME_LEVEL_19 = "1.9"; | |
24 | 25 | |
25 | 26 | // Default for 1.5.0 |
26 | 27 | public final static String RUNTIME_LEVEL_DEFAULT = RUNTIME_LEVEL_15; |
0 | /* ******************************************************************* | |
1 | * Copyright (c) 2018 Contributors | |
2 | * All rights reserved. | |
3 | * This program and the accompanying materials are made available | |
4 | * under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * ******************************************************************/ | |
8 | package org.aspectj.weaver; | |
9 | ||
10 | /** | |
11 | * Captures important runtime versions. Typically new versions are added here if something | |
12 | * changes in the runtime and the code generation may be able to do something different | |
13 | * (more optimal) for a later runtime. | |
14 | * | |
15 | * @author Andy Clement | |
16 | */ | |
17 | public enum RuntimeVersion { | |
18 | ||
19 | V1_2("1.2"), V1_5("1.5"), V1_6_10("1.6.10"), V1_9("1.9"); | |
20 | ||
21 | private String[] aliases = null; | |
22 | ||
23 | RuntimeVersion(String... aliases) { | |
24 | this.aliases = aliases; | |
25 | } | |
26 | ||
27 | public static RuntimeVersion getVersionFor(String version) { | |
28 | for (RuntimeVersion candidateVersion: values()) { | |
29 | if (candidateVersion.name().equals(version)) { | |
30 | return candidateVersion; | |
31 | } | |
32 | if (candidateVersion.aliases != null) { | |
33 | for (String alias: candidateVersion.aliases) { | |
34 | if (alias.equals(version)) { | |
35 | return candidateVersion; | |
36 | } | |
37 | } | |
38 | } | |
39 | } | |
40 | return null; | |
41 | } | |
42 | ||
43 | public boolean isThisVersionOrLater(RuntimeVersion version) { | |
44 | return this.compareTo(version) >= 0; | |
45 | } | |
46 | } |
109 | 109 | private boolean incrementalCompileCouldFollow = false; |
110 | 110 | |
111 | 111 | /** The level of the aspectjrt.jar the code we generate needs to run on */ |
112 | private String targetAspectjRuntimeLevel = Constants.RUNTIME_LEVEL_DEFAULT; | |
113 | ||
112 | public static final RuntimeVersion RUNTIME_LEVEL_DEFAULT = RuntimeVersion.V1_5; | |
113 | private RuntimeVersion targetAspectjRuntimeLevel = RUNTIME_LEVEL_DEFAULT; | |
114 | ||
114 | 115 | /** Flags for the new joinpoints that are 'optional': -Xjoinpoints:arrayconstruction -Xjoinpoints:synchronization */ |
115 | 116 | private boolean optionalJoinpoint_ArrayConstruction = false; |
116 | 117 | private boolean optionalJoinpoint_Synchronization = false; |
201 | 202 | /** |
202 | 203 | * Dump processing when a fatal error occurs |
203 | 204 | */ |
205 | @Override | |
204 | 206 | public void accept(Dump.IVisitor visitor) { |
205 | 207 | // visitor.visitObject("Extra configuration:"); |
206 | 208 | // visitor.visitList(extraConfiguration.); |
981 | 983 | } |
982 | 984 | |
983 | 985 | public void setTargetAspectjRuntimeLevel(String s) { |
984 | targetAspectjRuntimeLevel = s; | |
986 | targetAspectjRuntimeLevel = RuntimeVersion.getVersionFor(s); | |
985 | 987 | } |
986 | 988 | |
987 | 989 | public void setOptionalJoinpoints(String jps) { |
1004 | 1006 | return optionalJoinpoint_Synchronization; |
1005 | 1007 | } |
1006 | 1008 | |
1007 | public String getTargetAspectjRuntimeLevel() { | |
1009 | public RuntimeVersion getTargetAspectjRuntimeLevel() { | |
1008 | 1010 | return targetAspectjRuntimeLevel; |
1009 | 1011 | } |
1010 | 1012 | |
1011 | // OPTIMIZE are users falling foul of not supplying -1.5 and so targetting | |
1012 | // the old runtime? | |
1013 | // OPTIMIZE are users falling foul of not supplying -1.5 and so targetting the old runtime? | |
1013 | 1014 | public boolean isTargettingAspectJRuntime12() { |
1014 | 1015 | boolean b = false; // pr116679 |
1015 | 1016 | if (!isInJava5Mode()) { |
1016 | 1017 | b = true; |
1017 | 1018 | } else { |
1018 | b = getTargetAspectjRuntimeLevel().equals(org.aspectj.weaver.Constants.RUNTIME_LEVEL_12); | |
1019 | } | |
1020 | // System.err.println("Asked if targetting runtime 1.2 , returning: "+b); | |
1019 | b = (getTargetAspectjRuntimeLevel() == RuntimeVersion.V1_2); | |
1020 | } | |
1021 | 1021 | return b; |
1022 | 1022 | } |
1023 | 1023 |
71 | 71 | this.isExactDeclaringTypePattern = (declaringType instanceof ExactTypePattern); |
72 | 72 | } |
73 | 73 | |
74 | @Override | |
74 | 75 | public SignaturePattern resolveBindings(IScope scope, Bindings bindings) { |
75 | 76 | if (returnType != null) { |
76 | 77 | returnType = returnType.resolveBindings(scope, bindings, false, false); |
289 | 290 | * return a copy of this signature pattern in which every type variable reference is replaced by the corresponding entry in the |
290 | 291 | * map. |
291 | 292 | */ |
293 | @Override | |
292 | 294 | public SignaturePattern parameterizeWith(Map<String, UnresolvedType> typeVariableMap, World w) { |
293 | 295 | SignaturePattern ret = new SignaturePattern(kind, modifiers, returnType.parameterizeWith(typeVariableMap, w), declaringType |
294 | 296 | .parameterizeWith(typeVariableMap, w), name, parameterTypes.parameterizeWith(typeVariableMap, w), throwsPattern |
297 | 299 | return ret; |
298 | 300 | } |
299 | 301 | |
302 | @Override | |
300 | 303 | public boolean matches(Member joinPointSignature, World world, boolean allowBridgeMethods) { |
301 | 304 | // fail (or succeed!) fast tests... |
302 | 305 | if (joinPointSignature == null) { |
627 | 630 | |
628 | 631 | if (!parameterTypes.matches(resolvedParameters, TypePattern.STATIC, parameterAnnotationTypes).alwaysTrue()) { |
629 | 632 | // It could still be a match based on the generic sig parameter types of a parameterized type |
630 | if (!parameterTypes.matches(world.resolve(aConstructor.getGenericParameterTypes()), TypePattern.STATIC).alwaysTrue()) { | |
633 | if (!parameterTypes.matches(world.resolve(aConstructor.getGenericParameterTypes()), TypePattern.STATIC, parameterAnnotationTypes).alwaysTrue()) { | |
631 | 634 | return FuzzyBoolean.MAYBE; |
632 | 635 | // It could STILL be a match based on the erasure of the parameter types?? |
633 | 636 | // to be determined via test cases... |
967 | 970 | return annotationPattern; |
968 | 971 | } |
969 | 972 | |
973 | @Override | |
970 | 974 | public boolean isStarAnnotation() { |
971 | 975 | return annotationPattern == AnnotationTypePattern.ANY; |
972 | 976 | } |
980 | 984 | return isExactDeclaringTypePattern; |
981 | 985 | } |
982 | 986 | |
987 | @Override | |
983 | 988 | public boolean isMatchOnAnyName() { |
984 | 989 | return getName().isAny(); |
985 | 990 | } |
986 | 991 | |
992 | @Override | |
987 | 993 | public List<ExactTypePattern> getExactDeclaringTypes() { |
988 | 994 | if (declaringType instanceof ExactTypePattern) { |
989 | 995 | List<ExactTypePattern> l = new ArrayList<ExactTypePattern>(); |
994 | 1000 | } |
995 | 1001 | } |
996 | 1002 | |
1003 | @Override | |
997 | 1004 | public boolean couldEverMatch(ResolvedType type) { |
998 | 1005 | return declaringType.matches(type, TypePattern.STATIC).maybeTrue(); |
999 | 1006 | } |
0 | 0 | /* ******************************************************************* |
1 | 1 | * Copyright (c) 1999-2001 Xerox Corporation, |
2 | * 2002 Palo Alto Research Center, Incorporated (PARC). | |
2 | * 2002-2018 Palo Alto Research Center, Incorporated (PARC), Contributors | |
3 | 3 | * All rights reserved. |
4 | 4 | * This program and the accompanying materials are made available |
5 | 5 | * under the terms of the Eclipse Public License v1.0 |
7 | 7 | * http://www.eclipse.org/legal/epl-v10.html |
8 | 8 | * |
9 | 9 | * Contributors: |
10 | * Xerox/PARC initial implementation | |
10 | * Xerox/PARC initial implementation | |
11 | 11 | * Alex Vasseur new factory methods for variants of JP |
12 | * Abraham Nevado new factory methods for collapsed SJPs | |
12 | * Abraham Nevado new factory methods for collapsed SJPs | |
13 | * Andy Clement new factory methods that rely on LDC <class> | |
13 | 14 | * ******************************************************************/ |
14 | 15 | |
15 | 16 | package org.aspectj.runtime.reflect; |
37 | 38 | ClassLoader lookupClassLoader; |
38 | 39 | String filename; |
39 | 40 | int count; |
41 | ||
42 | private static final Class[] NO_TYPES = new Class[0]; | |
43 | private static final String[] NO_STRINGS = new String[0]; | |
40 | 44 | |
41 | 45 | static Hashtable prims = new Hashtable(); |
42 | 46 | static { |
54 | 58 | static Class makeClass(String s, ClassLoader loader) { |
55 | 59 | if (s.equals("*")) |
56 | 60 | return null; |
57 | Class ret = (Class) prims.get(s); | |
61 | Class ret = (Class)prims.get(s); | |
58 | 62 | if (ret != null) |
59 | 63 | return ret; |
60 | 64 | try { |
112 | 116 | Signature sig = this.makeMethodSig(modifiers, methodName, declaringType, paramTypes, paramNames, "", returnType); |
113 | 117 | return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(l, -1)); |
114 | 118 | } |
119 | ||
120 | // These are direct routes to creating thisJoinPoint and thisEnclosingJoinPoint objects | |
121 | // added in 1.9.1 | |
122 | ||
123 | public JoinPoint.StaticPart makeMethodSJP(String kind, int modifiers, String methodName, Class declaringType, Class[] paramTypes, String[] paramNames, Class[] exceptionTypes, Class returnType, int line) { | |
124 | Signature sig = this.makeMethodSig(modifiers, methodName, declaringType, paramTypes==null?NO_TYPES:paramTypes, | |
125 | paramNames==null?NO_STRINGS:paramNames, exceptionTypes==null?NO_TYPES:exceptionTypes, returnType == null?Void.TYPE:returnType); | |
126 | return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); | |
127 | } | |
128 | ||
129 | public JoinPoint.EnclosingStaticPart makeMethodESJP(String kind, int modifiers, String methodName, Class declaringType, Class[] paramTypes, String[] paramNames, Class[] exceptionTypes, Class returnType, int line) { | |
130 | Signature sig = this.makeMethodSig(modifiers, methodName, declaringType, paramTypes==null?NO_TYPES:paramTypes, | |
131 | paramNames==null?NO_STRINGS:paramNames, exceptionTypes==null?NO_TYPES:exceptionTypes, returnType == null?Void.TYPE:returnType); | |
132 | return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); | |
133 | } | |
134 | ||
135 | public JoinPoint.StaticPart makeConstructorSJP(String kind, int modifiers, Class declaringType, Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes, int line) { | |
136 | ConstructorSignatureImpl sig = new ConstructorSignatureImpl(modifiers, declaringType, parameterTypes==null?NO_TYPES:parameterTypes, parameterNames==null?NO_STRINGS:parameterNames, | |
137 | exceptionTypes==null?NO_TYPES:exceptionTypes); | |
138 | return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); | |
139 | } | |
140 | ||
141 | public JoinPoint.EnclosingStaticPart makeConstructorESJP(String kind, int modifiers, Class declaringType, Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes, int line) { | |
142 | ConstructorSignatureImpl sig = new ConstructorSignatureImpl(modifiers, declaringType, parameterTypes==null?NO_TYPES:parameterTypes, parameterNames==null?NO_STRINGS:parameterNames, | |
143 | exceptionTypes==null?NO_TYPES:exceptionTypes); | |
144 | return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); | |
145 | } | |
146 | ||
147 | public JoinPoint.StaticPart makeCatchClauseSJP(String kind, Class declaringType, Class parameterType, String parameterName, int line) { | |
148 | CatchClauseSignatureImpl sig = new CatchClauseSignatureImpl(declaringType, parameterType, parameterName==null?"":parameterName); | |
149 | return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); | |
150 | } | |
151 | ||
152 | public JoinPoint.EnclosingStaticPart makeCatchClauseESJP(String kind, Class declaringType, Class parameterType, String parameterName, int line) { | |
153 | CatchClauseSignatureImpl sig = new CatchClauseSignatureImpl(declaringType, parameterType, parameterName==null?"":parameterName); | |
154 | return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); | |
155 | } | |
156 | ||
157 | public JoinPoint.StaticPart makeFieldSJP(String kind, int modifiers, String name, Class declaringType, Class fieldType, int line) { | |
158 | FieldSignatureImpl sig = new FieldSignatureImpl(modifiers, name, declaringType, fieldType); | |
159 | return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); | |
160 | } | |
161 | ||
162 | public JoinPoint.EnclosingStaticPart makeFieldESJP(String kind, int modifiers, String name, Class declaringType, Class fieldType, int line) { | |
163 | FieldSignatureImpl sig = new FieldSignatureImpl(modifiers, name, declaringType, fieldType); | |
164 | return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); | |
165 | } | |
166 | ||
167 | public JoinPoint.StaticPart makeInitializerSJP(String kind, int modifiers, Class declaringType, int line) { | |
168 | InitializerSignatureImpl sig = new InitializerSignatureImpl(modifiers, declaringType); | |
169 | return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); | |
170 | } | |
171 | ||
172 | public JoinPoint.EnclosingStaticPart makeInitializerESJP(String kind, int modifiers, Class declaringType, int line) { | |
173 | InitializerSignatureImpl sig = new InitializerSignatureImpl(modifiers, declaringType); | |
174 | return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); | |
175 | } | |
176 | ||
177 | public JoinPoint.StaticPart makeLockSJP(String kind, Class declaringType, int line) { | |
178 | LockSignatureImpl sig = new LockSignatureImpl(declaringType); | |
179 | return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); | |
180 | } | |
181 | ||
182 | public JoinPoint.EnclosingStaticPart makeLockESJP(String kind, Class declaringType, int line) { | |
183 | LockSignatureImpl sig = new LockSignatureImpl(declaringType); | |
184 | return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); | |
185 | } | |
186 | ||
187 | public JoinPoint.StaticPart makeUnlockSJP(String kind, Class declaringType, int line) { | |
188 | UnlockSignatureImpl sig = new UnlockSignatureImpl(declaringType); | |
189 | return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); | |
190 | } | |
191 | ||
192 | public JoinPoint.EnclosingStaticPart makeUnlockESJP(String kind, Class declaringType, int line) { | |
193 | UnlockSignatureImpl sig = new UnlockSignatureImpl(declaringType); | |
194 | return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); | |
195 | } | |
196 | ||
197 | public JoinPoint.StaticPart makeAdviceSJP(String kind, int modifiers, String name, Class declaringType, Class[] parameterTypes, | |
198 | String[] parameterNames, Class[] exceptionTypes, Class returnType, int line) { | |
199 | AdviceSignatureImpl sig = new AdviceSignatureImpl(modifiers, name, declaringType, | |
200 | parameterTypes==null?NO_TYPES:parameterTypes, | |
201 | parameterNames==null?NO_STRINGS:parameterNames, | |
202 | exceptionTypes==null?NO_TYPES:exceptionTypes, | |
203 | returnType==null?Void.TYPE:returnType); | |
204 | return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); | |
205 | } | |
206 | ||
207 | public JoinPoint.EnclosingStaticPart makeAdviceESJP(String kind, int modifiers, String name, Class declaringType, Class[] parameterTypes, | |
208 | String[] parameterNames, Class[] exceptionTypes, Class returnType, int line) { | |
209 | AdviceSignatureImpl sig = new AdviceSignatureImpl(modifiers, name, declaringType, | |
210 | parameterTypes==null?NO_TYPES:parameterTypes, | |
211 | parameterNames==null?NO_STRINGS:parameterNames, | |
212 | exceptionTypes==null?NO_TYPES:exceptionTypes, | |
213 | returnType==null?Void.TYPE:returnType); | |
214 | return new JoinPointImpl.EnclosingStaticPartImpl(count++, kind, sig, makeSourceLoc(line, -1)); | |
215 | } | |
216 | ||
217 | // --- | |
115 | 218 | |
116 | 219 | public JoinPoint.StaticPart makeSJP(String kind, Signature sig, SourceLocation loc) { |
117 | 220 | return new JoinPointImpl.StaticPartImpl(count++, kind, sig, loc); |
180 | 283 | ret.setLookupClassLoader(lookupClassLoader); |
181 | 284 | return ret; |
182 | 285 | } |
183 | ||
286 | ||
184 | 287 | public MethodSignature makeMethodSig(String modifiers, String methodName, String declaringType, String paramTypes, |
185 | 288 | String paramNames, String exceptionTypes, String returnType) { |
289 | Class declaringTypeClass = makeClass(declaringType, lookupClassLoader); | |
290 | return makeMethodSig(modifiers, methodName, declaringTypeClass, paramTypes, paramNames, exceptionTypes, returnType); | |
291 | } | |
292 | ||
293 | public MethodSignature makeMethodSig(String modifiers, String methodName, Class declaringTypeClass, String paramTypes, | |
294 | String paramNames, String exceptionTypes, String returnType) { | |
186 | 295 | int modifiersAsInt = Integer.parseInt(modifiers, 16); |
187 | ||
188 | Class declaringTypeClass = makeClass(declaringType, lookupClassLoader); | |
189 | 296 | |
190 | 297 | StringTokenizer st = new StringTokenizer(paramTypes, ":"); |
191 | 298 | int numParams = st.countTokens(); |
215 | 322 | |
216 | 323 | public MethodSignature makeMethodSig(int modifiers, String name, Class declaringType, Class[] parameterTypes, |
217 | 324 | String[] parameterNames, Class[] exceptionTypes, Class returnType) { |
218 | MethodSignatureImpl ret = new MethodSignatureImpl(modifiers, name, declaringType, parameterTypes, parameterNames, | |
219 | exceptionTypes, returnType); | |
325 | MethodSignatureImpl ret = new MethodSignatureImpl(modifiers, name, declaringType, parameterTypes==null?NO_TYPES:parameterTypes, parameterNames, | |
326 | exceptionTypes == null?NO_TYPES:exceptionTypes, returnType); | |
220 | 327 | ret.setLookupClassLoader(lookupClassLoader); |
221 | 328 | return ret; |
222 | 329 | } |
722 | 722 | |
723 | 723 | // / The repository interface methods |
724 | 724 | |
725 | @Override | |
725 | 726 | public JavaClass findClass(String className) { |
726 | 727 | return lookupJavaClass(classPath, className); |
727 | 728 | } |
728 | 729 | |
730 | @Override | |
729 | 731 | public JavaClass loadClass(String className) throws ClassNotFoundException { |
730 | 732 | return lookupJavaClass(classPath, className); |
731 | 733 | } |
732 | 734 | |
735 | @Override | |
733 | 736 | public void storeClass(JavaClass clazz) { |
734 | 737 | // doesn't need to do anything |
735 | 738 | } |
736 | 739 | |
740 | @Override | |
737 | 741 | public void removeClass(JavaClass clazz) { |
738 | 742 | throw new RuntimeException("Not implemented"); |
739 | 743 | } |
740 | 744 | |
745 | @Override | |
741 | 746 | public JavaClass loadClass(Class clazz) throws ClassNotFoundException { |
742 | 747 | throw new RuntimeException("Not implemented"); |
743 | 748 | } |
744 | 749 | |
750 | @Override | |
745 | 751 | public void clear() { |
746 | 752 | delegate.clear(); |
747 | 753 | // throw new RuntimeException("Not implemented"); |
1290 | 1296 | |
1291 | 1297 | } |
1292 | 1298 | |
1299 | @Override | |
1293 | 1300 | public TypeMap getTypeMap() { |
1294 | 1301 | return typeMap; |
1295 | 1302 | } |
1296 | 1303 | |
1304 | @Override | |
1297 | 1305 | public boolean isLoadtimeWeaving() { |
1298 | 1306 | return false; |
1299 | 1307 | } |
1305 | 1313 | typeDelegateResolvers.add(typeDelegateResolver); |
1306 | 1314 | } |
1307 | 1315 | |
1316 | @Override | |
1308 | 1317 | public void classWriteEvent(char[][] compoundName) { |
1309 | 1318 | typeMap.classWriteEvent(new String(CharOperation.concatWith(compoundName, '.'))); |
1310 | 1319 | } |
52 | 52 | import org.aspectj.bridge.IMessage; |
53 | 53 | import org.aspectj.bridge.ISourceLocation; |
54 | 54 | import org.aspectj.bridge.SourceLocation; |
55 | import org.aspectj.util.LangUtil; | |
56 | 55 | import org.aspectj.weaver.AjAttribute; |
57 | 56 | import org.aspectj.weaver.AjAttribute.WeaverState; |
58 | 57 | import org.aspectj.weaver.AjAttribute.WeaverVersionInfo; |
59 | 58 | import org.aspectj.weaver.BCException; |
60 | 59 | import org.aspectj.weaver.Member; |
60 | import org.aspectj.weaver.MemberKind; | |
61 | 61 | import org.aspectj.weaver.NameMangler; |
62 | 62 | import org.aspectj.weaver.ResolvedMember; |
63 | 63 | import org.aspectj.weaver.ResolvedType; |
64 | import org.aspectj.weaver.RuntimeVersion; | |
64 | 65 | import org.aspectj.weaver.Shadow; |
65 | 66 | import org.aspectj.weaver.SignatureUtils; |
66 | 67 | import org.aspectj.weaver.TypeVariable; |
78 | 79 | * Aspect. |
79 | 80 | */ |
80 | 81 | public final class LazyClassGen { |
82 | ||
83 | private static final Type[] ARRAY_7STRING_INT = new Type[] { Type.STRING, Type.STRING, Type.STRING, Type.STRING, Type.STRING, | |
84 | Type.STRING, Type.STRING, Type.INT }; | |
85 | ||
86 | private static final Type[] ARRAY_8STRING_INT = new Type[] { Type.STRING, Type.STRING, Type.STRING, Type.STRING, Type.STRING, | |
87 | Type.STRING, Type.STRING, Type.STRING, Type.INT }; | |
88 | ||
89 | private static final Type[] PARAMSIGNATURE_MAKESJP_METHOD = new Type[] { | |
90 | Type.STRING, Type.INT, Type.STRING, Type.CLASS, Type.CLASS_ARRAY, Type.STRING_ARRAY, Type.CLASS_ARRAY, Type.CLASS, Type.INT | |
91 | }; | |
92 | ||
93 | private static final Type[] PARAMSIGNATURE_MAKESJP_CONSTRUCTOR = new Type[] { | |
94 | Type.STRING, Type.INT, Type.CLASS, Type.CLASS_ARRAY, Type.STRING_ARRAY, Type.CLASS_ARRAY, Type.INT | |
95 | }; | |
96 | ||
97 | private static final Type[] PARAMSIGNATURE_MAKESJP_CATCHCLAUSE = new Type[] { | |
98 | Type.STRING, Type.CLASS, Type.CLASS, Type.STRING, Type.INT | |
99 | }; | |
100 | ||
101 | private static final Type[] PARAMSIGNATURE_MAKESJP_FIELD = new Type[] { | |
102 | Type.STRING, Type.INT, Type.STRING, Type.CLASS, Type.CLASS, Type.INT | |
103 | }; | |
104 | ||
105 | private static final Type[] PARAMSIGNATURE_MAKESJP_INITIALIZER = new Type[] { | |
106 | Type.STRING, Type.INT, Type.CLASS, Type.INT | |
107 | }; | |
108 | ||
109 | private static final Type[] PARAMSIGNATURE_MAKESJP_MONITOR = new Type[] { | |
110 | Type.STRING, Type.CLASS, Type.INT | |
111 | }; | |
112 | ||
113 | private static final Type[] PARAMSIGNATURE_MAKESJP_ADVICE = new Type[] { | |
114 | Type.STRING, Type.INT, Type.STRING, Type.CLASS, Type.CLASS_ARRAY, Type.STRING_ARRAY, | |
115 | Type.CLASS_ARRAY, Type.CLASS, Type.INT | |
116 | }; | |
117 | ||
118 | ||
119 | ||
120 | ||
81 | 121 | |
82 | 122 | private static final int ACC_SYNTHETIC = 0x1000; |
83 | 123 | |
1231 | 1271 | |
1232 | 1272 | List<Map.Entry<BcelShadow, Field>> entries = new ArrayList<Map.Entry<BcelShadow, Field>>(tjpFields.entrySet()); |
1233 | 1273 | Collections.sort(entries, new Comparator<Map.Entry<BcelShadow, Field>>() { |
1274 | @Override | |
1234 | 1275 | public int compare(Map.Entry<BcelShadow, Field> a, Map.Entry<BcelShadow, Field> b) { |
1235 | 1276 | return (a.getValue()).getName().compareTo((b.getValue()).getName()); |
1236 | 1277 | } |
1252 | 1293 | } |
1253 | 1294 | |
1254 | 1295 | private void initializeTjp(InstructionFactory fact, InstructionList list, Field field, BcelShadow shadow) { |
1296 | if (world.getTargetAspectjRuntimeLevel() == RuntimeVersion.V1_9) { | |
1297 | initializeTjpOptimal(fact, list, field, shadow); | |
1298 | return; | |
1299 | } | |
1255 | 1300 | boolean fastSJP = false; |
1256 | 1301 | // avoid fast SJP if it is for an enclosing joinpoint |
1257 | 1302 | boolean isFastSJPAvailable = shadow.getWorld().isTargettingRuntime1_6_10() |
1273 | 1318 | String signatureMakerName = SignatureUtils.getSignatureMakerName(sig); |
1274 | 1319 | ObjectType signatureType = new ObjectType(SignatureUtils.getSignatureType(sig)); |
1275 | 1320 | UnresolvedType[] exceptionTypes = null; |
1276 | if (world.isTargettingAspectJRuntime12()) { // TAG:SUPPORTING12: We | |
1277 | // didn't have optimized | |
1278 | // factory methods in 1.2 | |
1321 | if (world.isTargettingAspectJRuntime12()) { // TAG:SUPPORTING12: We didn't have optimized factory methods in 1.2 | |
1279 | 1322 | list.append(InstructionFactory.PUSH(cp, SignatureUtils.getSignatureString(sig, shadow.getWorld()))); |
1280 | 1323 | list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, Type.STRINGARRAY1, |
1281 | 1324 | Constants.INVOKEVIRTUAL)); |
1369 | 1412 | list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, Type.STRINGARRAY2, |
1370 | 1413 | Constants.INVOKEVIRTUAL)); |
1371 | 1414 | } else { |
1415 | // TODO looks like this block is unused code | |
1372 | 1416 | list.append(InstructionFactory.PUSH(cp, SignatureUtils.getSignatureString(sig, shadow.getWorld()))); |
1373 | 1417 | list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, Type.STRINGARRAY1, |
1374 | 1418 | Constants.INVOKEVIRTUAL)); |
1414 | 1458 | } |
1415 | 1459 | } |
1416 | 1460 | |
1417 | private static final Type[] ARRAY_7STRING_INT = new Type[] { Type.STRING, Type.STRING, Type.STRING, Type.STRING, Type.STRING, | |
1418 | Type.STRING, Type.STRING, Type.INT }; | |
1419 | private static final Type[] ARRAY_8STRING_INT = new Type[] { Type.STRING, Type.STRING, Type.STRING, Type.STRING, Type.STRING, | |
1420 | Type.STRING, Type.STRING, Type.STRING, Type.INT }; | |
1461 | public String getFactoryMethod(Field field, BcelShadow shadow) { | |
1462 | StringBuilder b = new StringBuilder(); | |
1463 | b.append("make"); | |
1464 | MemberKind kind = shadow.getSignature().getKind(); | |
1465 | if (kind.equals(Member.METHOD)) { | |
1466 | b.append("Method"); | |
1467 | } else if (kind.equals(Member.CONSTRUCTOR)) { | |
1468 | b.append("Constructor"); | |
1469 | } else if (kind.equals(Member.HANDLER)) { | |
1470 | b.append("CatchClause"); | |
1471 | } else if (kind.equals(Member.FIELD)) { | |
1472 | b.append("Field"); | |
1473 | } else if (kind.equals(Member.STATIC_INITIALIZATION)) { | |
1474 | b.append("Initializer"); | |
1475 | } else if (kind.equals(Member.MONITORENTER)) { | |
1476 | b.append("Lock"); | |
1477 | } else if (kind.equals(Member.MONITOREXIT)) { | |
1478 | b.append("Unlock"); | |
1479 | } else if (kind.equals(Member.ADVICE)) { | |
1480 | b.append("Advice"); | |
1481 | } else { | |
1482 | throw new IllegalStateException(kind.toString()); | |
1483 | } | |
1484 | if (staticTjpType.equals(field.getType())) { | |
1485 | b.append("SJP"); | |
1486 | } else if (enclosingStaticTjpType.equals(field.getType())) { | |
1487 | b.append("ESJP"); | |
1488 | } | |
1489 | return b.toString(); | |
1490 | } | |
1491 | ||
1492 | /** | |
1493 | * Generate optimal joinpoint initialization code. | |
1494 | * | |
1495 | * As of version 1.9.1 the runtime includes new factory methods for joinpoints that take classes, not strings | |
1496 | * and using them requires different code generation. Using these instead of the old ones means we can avoid | |
1497 | * deferred classloading for these types. By using the LDC instruction that loads classes, it also means | |
1498 | * anything modifying woven code and changing type names will also pick up on these references. | |
1499 | */ | |
1500 | private void initializeTjpOptimal(InstructionFactory fact, InstructionList list, Field field, BcelShadow shadow) { | |
1501 | list.append(InstructionFactory.createLoad(factoryType, 0)); | |
1502 | pushString(list, shadow.getKind().getName()); | |
1503 | String factoryMethod = getFactoryMethod(field, shadow); | |
1504 | Member sig = shadow.getSignature(); | |
1505 | BcelWorld w = shadow.getWorld(); | |
1506 | ||
1507 | if (sig.getKind().equals(Member.METHOD)) { | |
1508 | pushInt(list, sig.getModifiers(w)); | |
1509 | pushString(list, sig.getName()); | |
1510 | pushClass(list, sig.getDeclaringType()); | |
1511 | pushClasses(list, sig.getParameterTypes()); | |
1512 | pushStrings(list, sig.getParameterNames(w)); | |
1513 | pushClasses(list, sig.getExceptions(w)); | |
1514 | pushClass(list, sig.getReturnType()); | |
1515 | pushInt(list, shadow.getSourceLine()); | |
1516 | list.append(fact.createInvoke(factoryType.getClassName(), factoryMethod, field.getType(), | |
1517 | PARAMSIGNATURE_MAKESJP_METHOD, Constants.INVOKEVIRTUAL)); | |
1518 | } else if (sig.getKind().equals(Member.CONSTRUCTOR)) { | |
1519 | if (w.isJoinpointArrayConstructionEnabled() && sig.getDeclaringType().isArray()) { | |
1520 | pushInt(list, Modifier.PUBLIC); | |
1521 | pushClass(list, sig.getDeclaringType()); | |
1522 | pushClasses(list, sig.getParameterTypes()); | |
1523 | pushStrings(list, null); | |
1524 | pushClasses(list, null); | |
1525 | } else { | |
1526 | pushInt(list, sig.getModifiers(w)); | |
1527 | pushClass(list, sig.getDeclaringType()); | |
1528 | pushClasses(list, sig.getParameterTypes()); | |
1529 | pushStrings(list, sig.getParameterNames(w)); | |
1530 | pushClasses(list, sig.getExceptions(w)); | |
1531 | } | |
1532 | pushInt(list, shadow.getSourceLine()); | |
1533 | list.append(fact.createInvoke(factoryType.getClassName(), factoryMethod, field.getType(), | |
1534 | PARAMSIGNATURE_MAKESJP_CONSTRUCTOR, Constants.INVOKEVIRTUAL)); | |
1535 | } else if (sig.getKind().equals(Member.HANDLER)) { | |
1536 | pushClass(list, sig.getDeclaringType()); | |
1537 | pushClass(list, sig.getParameterTypes()[0]); | |
1538 | String pname = null; | |
1539 | String[] pnames = sig.getParameterNames(w); | |
1540 | if (pnames != null && pnames.length>0) { | |
1541 | pname = pnames[0]; | |
1542 | } | |
1543 | pushString(list, pname); | |
1544 | pushInt(list, shadow.getSourceLine()); | |
1545 | list.append(fact.createInvoke(factoryType.getClassName(), factoryMethod, field.getType(), | |
1546 | PARAMSIGNATURE_MAKESJP_CATCHCLAUSE, Constants.INVOKEVIRTUAL)); | |
1547 | } else if (sig.getKind().equals(Member.FIELD)) { | |
1548 | pushInt(list, sig.getModifiers(w)); | |
1549 | pushString(list, sig.getName()); | |
1550 | // see pr227401 | |
1551 | UnresolvedType dType = sig.getDeclaringType(); | |
1552 | if (dType.getTypekind() == TypeKind.PARAMETERIZED || dType.getTypekind() == TypeKind.GENERIC) { | |
1553 | dType = sig.getDeclaringType().resolve(world).getGenericType(); | |
1554 | } | |
1555 | pushClass(list, dType); | |
1556 | pushClass(list, sig.getReturnType()); | |
1557 | pushInt(list,shadow.getSourceLine()); | |
1558 | list.append(fact.createInvoke(factoryType.getClassName(), factoryMethod, field.getType(), | |
1559 | PARAMSIGNATURE_MAKESJP_FIELD, Constants.INVOKEVIRTUAL)); | |
1560 | } else if (sig.getKind().equals(Member.STATIC_INITIALIZATION)) { | |
1561 | pushInt(list, sig.getModifiers(w)); | |
1562 | pushClass(list, sig.getDeclaringType()); | |
1563 | pushInt(list, shadow.getSourceLine()); | |
1564 | list.append(fact.createInvoke(factoryType.getClassName(), factoryMethod, field.getType(), | |
1565 | PARAMSIGNATURE_MAKESJP_INITIALIZER, Constants.INVOKEVIRTUAL)); | |
1566 | } else if (sig.getKind().equals(Member.MONITORENTER)) { | |
1567 | pushClass(list, sig.getDeclaringType()); | |
1568 | pushInt(list, shadow.getSourceLine()); | |
1569 | list.append(fact.createInvoke(factoryType.getClassName(), factoryMethod, field.getType(), | |
1570 | PARAMSIGNATURE_MAKESJP_MONITOR, Constants.INVOKEVIRTUAL)); | |
1571 | } else if (sig.getKind().equals(Member.MONITOREXIT)) { | |
1572 | pushClass(list, sig.getDeclaringType()); | |
1573 | pushInt(list, shadow.getSourceLine()); | |
1574 | list.append(fact.createInvoke(factoryType.getClassName(), factoryMethod, field.getType(), | |
1575 | PARAMSIGNATURE_MAKESJP_MONITOR, Constants.INVOKEVIRTUAL)); | |
1576 | } else if (sig.getKind().equals(Member.ADVICE)) { | |
1577 | pushInt(list, sig.getModifiers(w)); | |
1578 | pushString(list, sig.getName()); | |
1579 | pushClass(list, sig.getDeclaringType()); | |
1580 | pushClasses(list, sig.getParameterTypes()); | |
1581 | pushStrings(list, sig.getParameterNames(w)); | |
1582 | pushClasses(list, sig.getExceptions(w)); | |
1583 | pushClass(list, sig.getReturnType()); | |
1584 | pushInt(list, shadow.getSourceLine()); | |
1585 | list.append(fact.createInvoke(factoryType.getClassName(), factoryMethod, field.getType(), | |
1586 | PARAMSIGNATURE_MAKESJP_ADVICE, Constants.INVOKEVIRTUAL)); | |
1587 | } else { | |
1588 | throw new IllegalStateException("not sure what to do: "+shadow); | |
1589 | } | |
1590 | list.append(fact.createFieldAccess(getClassName(), field.getName(), field.getType(), Constants.PUTSTATIC)); | |
1591 | } | |
1592 | ||
1593 | private void pushStrings(InstructionList list, String[] strings) { | |
1594 | // Build an array loaded with the strings | |
1595 | if (strings == null || strings.length == 0) { | |
1596 | list.append(InstructionFactory.ACONST_NULL); | |
1597 | } else { | |
1598 | list.append(InstructionFactory.PUSH(cp, strings.length)); | |
1599 | list.append(fact.createNewArray(Type.STRING, (short)1)); | |
1600 | for (int s=0;s<strings.length;s++) { | |
1601 | list.append(InstructionFactory.DUP); | |
1602 | list.append(InstructionFactory.PUSH(cp, s)); | |
1603 | list.append(InstructionFactory.PUSH(cp, strings[s])); | |
1604 | list.append(InstructionFactory.AASTORE); | |
1605 | } | |
1606 | } | |
1607 | } | |
1608 | ||
1609 | private void pushClass(InstructionList list, UnresolvedType type) { | |
1610 | if (type.isPrimitiveType()) { | |
1611 | if (type.getSignature().equals("I")) { | |
1612 | list.append(fact.createGetStatic("java/lang/Integer","TYPE", Type.CLASS)); | |
1613 | } else if (type.getSignature().equals("D")) { | |
1614 | list.append(fact.createGetStatic("java/lang/Double","TYPE", Type.CLASS)); | |
1615 | } else if (type.getSignature().equals("S")) { | |
1616 | list.append(fact.createGetStatic("java/lang/Short","TYPE", Type.CLASS)); | |
1617 | } else if (type.getSignature().equals("J")) { | |
1618 | list.append(fact.createGetStatic("java/lang/Long","TYPE", Type.CLASS)); | |
1619 | } else if (type.getSignature().equals("F")) { | |
1620 | list.append(fact.createGetStatic("java/lang/Float","TYPE", Type.CLASS)); | |
1621 | } else if (type.getSignature().equals("C")) { | |
1622 | list.append(fact.createGetStatic("java/lang/Character","TYPE", Type.CLASS)); | |
1623 | } else if (type.getSignature().equals("B")) { | |
1624 | list.append(fact.createGetStatic("java/lang/Byte","TYPE", Type.CLASS)); | |
1625 | } else if (type.getSignature().equals("Z")) { | |
1626 | list.append(fact.createGetStatic("java/lang/Boolean","TYPE", Type.CLASS)); | |
1627 | } else if (type.getSignature().equals("V")) { | |
1628 | list.append(InstructionFactory.ACONST_NULL); | |
1629 | } | |
1630 | return; | |
1631 | } | |
1632 | String classString = makeLdcClassString(type); | |
1633 | if (classString == null) { | |
1634 | list.append(InstructionFactory.ACONST_NULL); | |
1635 | } else { | |
1636 | list.append(fact.PUSHCLASS(cp, classString)); | |
1637 | } | |
1638 | } | |
1639 | ||
1640 | private void pushClasses(InstructionList list, UnresolvedType[] types) { | |
1641 | // Build an array loaded with the class objects | |
1642 | if (types == null || types.length == 0) { | |
1643 | list.append(InstructionFactory.ACONST_NULL); | |
1644 | } else { | |
1645 | list.append(InstructionFactory.PUSH(cp, types.length)); | |
1646 | list.append(fact.createNewArray(Type.CLASS, (short)1)); | |
1647 | for (int t=0;t<types.length;t++) { | |
1648 | list.append(InstructionFactory.DUP); | |
1649 | list.append(InstructionFactory.PUSH(cp, t)); | |
1650 | pushClass(list, types[t]); | |
1651 | list.append(InstructionFactory.AASTORE); | |
1652 | } | |
1653 | } | |
1654 | } | |
1655 | ||
1656 | private final void pushString(InstructionList list, String string) { | |
1657 | list.append(InstructionFactory.PUSH(cp, string)); | |
1658 | } | |
1659 | ||
1660 | private final void pushInt(InstructionList list, int value) { | |
1661 | list.append(InstructionFactory.PUSH(cp, value)); | |
1662 | } | |
1421 | 1663 | |
1422 | 1664 | protected String makeString(int i) { |
1423 | 1665 | return Integer.toString(i, 16); // ??? expensive |
1435 | 1677 | } else { |
1436 | 1678 | return t.getName(); |
1437 | 1679 | } |
1680 | } | |
1681 | } | |
1682 | ||
1683 | protected String makeLdcClassString(UnresolvedType type) { | |
1684 | if (type.isVoid() || type.isPrimitiveType()) { | |
1685 | return null; | |
1686 | } | |
1687 | if (type.isArray()) { | |
1688 | return type.getSignature(); | |
1689 | } else { | |
1690 | if (type.isParameterizedType()) { | |
1691 | type = type.getRawType(); | |
1692 | } | |
1693 | String signature = type.getSignature(); | |
1694 | if (signature.length() ==1 ) { | |
1695 | return signature; | |
1696 | } | |
1697 | return signature.substring(1,signature.length()-1); | |
1438 | 1698 | } |
1439 | 1699 | } |
1440 | 1700 |
0 | 0 | /* ******************************************************************* |
1 | * Copyright (c) 2008 Contributors | |
1 | * Copyright (c) 2008, 2018 Contributors | |
2 | 2 | * All rights reserved. |
3 | 3 | * This program and the accompanying materials are made available |
4 | 4 | * under the terms of the Eclipse Public License v1.0 |
14 | 14 | import org.aspectj.weaver.UnresolvedType; |
15 | 15 | import org.aspectj.weaver.World; |
16 | 16 | |
17 | import aj.org.objectweb.asm.*; | |
17 | import aj.org.objectweb.asm.ClassReader; | |
18 | import aj.org.objectweb.asm.ClassVisitor; | |
19 | import aj.org.objectweb.asm.ClassWriter; | |
20 | import aj.org.objectweb.asm.MethodVisitor; | |
21 | import aj.org.objectweb.asm.Opcodes; | |
18 | 22 | |
19 | 23 | /** |
20 | 24 | * Uses asm to add the stack map attribute to methods in a class. The class is passed in as pure byte data and then a reader/writer |
78 | 82 | |
79 | 83 | |
80 | 84 | // Implementation of getCommonSuperClass() that avoids Class.forName() |
85 | @Override | |
81 | 86 | protected String getCommonSuperClass(final String type1, final String type2) { |
82 | 87 | |
83 | 88 | ResolvedType resolvedType1 = world.resolve(UnresolvedType.forName(type1.replace('/', '.'))); |
96 | 101 | } else { |
97 | 102 | do { |
98 | 103 | resolvedType1 = resolvedType1.getSuperclass(); |
104 | if (resolvedType1 == null) { | |
105 | // This happens if some types are missing, the getSuperclass() call on | |
106 | // MissingResolvedTypeWithKnownSignature will return the Missing type which | |
107 | // in turn returns a superclass of null. By returning Object here it | |
108 | // should surface the cantFindType message raised in the first problematic | |
109 | // getSuperclass call | |
110 | return "java/lang/Object"; | |
111 | } | |
99 | 112 | if (resolvedType1.isParameterizedOrGenericType()) { |
100 | 113 | resolvedType1 = resolvedType1.getRawType(); |
101 | 114 | } |