Codebase list aspectj / ee0a7a2
New upstream version 1.9.0 Emmanuel Bourg 5 years ago
19 changed file(s) with 605 addition(s) and 63 deletion(s). Raw diff Collapse all Expand all
760760 iList.append(new InstructionCP(Instruction.LDC_W, classIndex));
761761 }
762762 } else {
763 className = className.replace('/', '.');
763764 iList.append(InstructionFactory.PUSH(cp, className));
764765 iList.append(this.createInvoke("java.lang.Class", "forName", ObjectType.CLASS, Type.STRINGARRAY1,
765766 Constants.INVOKESTATIC));
8888 public static final BasicType CHAR = new BasicType(Constants.T_CHAR);
8989 public static final ObjectType OBJECT = new ObjectType("java.lang.Object");
9090 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);
9394 public static final ObjectType STRINGBUFFER = new ObjectType("java.lang.StringBuffer");
9495 public static final ObjectType STRINGBUILDER = new ObjectType("java.lang.StringBuilder");
9596 public static final ObjectType THROWABLE = new ObjectType("java.lang.Throwable");
128129 commonTypes.put(CLASS.getSignature(), CLASS);
129130 commonTypes.put(OBJECT.getSignature(), OBJECT);
130131 commonTypes.put(STRING_ARRAY.getSignature(), STRING_ARRAY);
132 commonTypes.put(CLASS_ARRAY.getSignature(), CLASS_ARRAY);
131133 commonTypes.put(OBJECT_ARRAY.getSignature(), OBJECT_ARRAY);
132134 commonTypes.put(INTEGER.getSignature(), INTEGER);
133135 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
00 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
11 <html> <head>
2 <title>AspectJ 1.9.0.RC4 Readme</title>
2 <title>AspectJ 1.9.0 Readme</title>
33 <style type="text/css">
44 <!--
55 P { margin-left: 20px; }
1818 </small></div>
1919 <p>The full list of resolved issues in 1.9.0 is available
2020 <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>
2156
2257 <h1>AspectJ 1.9.0.RC4</h1>
2358
281316 <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>
282317 </ul>
283318
319 <br><br>
320
321
284322 <!-- ============================== -->
285323 </body>
286324 </html>
6565 /**
6666 * Initialization
6767 */
68 @Override
6869 public void initialize() {
6970
7071 }
7980 * @param loader
8081 * @return woven bytes
8182 */
83 @Override
8284 public byte[] preProcess(String className, byte[] bytes, ClassLoader loader, ProtectionDomain protectionDomain) {
8385 // TODO AV needs to doc that
8486 if (loader == null || className == null || loader.getClass().getName().equals(deleLoader)) {
170172 return instance;
171173 }
172174
175 @Override
173176 public boolean equals(Object obj) {
174177 if (!(obj instanceof AdaptorKey)) {
175178 return false;
180183 && loaderClass.equals(other.loaderClass);
181184 }
182185
186 @Override
183187 public int hashCode() {
184188 return hashValue;
185189 }
300304 if (loader.equals(myClassLoader)){
301305 adaptor = myClassLoaderAdaptor;
302306 } else {
303 adaptor = (ExplicitlyInitializedClassLoaderWeavingAdaptor) weavingAdaptors.get(adaptorKey);
307 adaptor = weavingAdaptors.get(adaptorKey);
304308 }
305309 if (adaptor == null) {
306310 // create it and put it back in the weavingAdaptors map but avoid any kind of instantiation
369373 ((ClassLoaderWeavingAdaptor) WeaverContainer.getWeaver(loader, weavingContext)).flushGeneratedClasses();
370374 }
371375
376 @Override
377 public void prepareForRedefinition(ClassLoader loader, String className) {
378 ((ClassLoaderWeavingAdaptor) WeaverContainer.getWeaver(loader, weavingContext)).flushGeneratedClassesFor(className);
379 }
380
372381 }
1111 import java.io.IOException;
1212 import java.io.InputStream;
1313 import java.lang.reflect.Field;
14 import java.lang.reflect.InvocationTargetException;
15 import java.lang.reflect.Method;
1614 import java.net.MalformedURLException;
1715 import java.net.URL;
1816 import java.security.ProtectionDomain;
2321 import java.util.Iterator;
2422 import java.util.LinkedList;
2523 import java.util.List;
24 import java.util.Map;
25 import java.util.Map.Entry;
2626 import java.util.Properties;
2727 import java.util.Set;
2828 import java.util.StringTokenizer;
113113 *
114114 * @deprecated
115115 */
116 @Deprecated
116117 public ClassLoaderWeavingAdaptor(final ClassLoader deprecatedLoader, final IWeavingContext deprecatedContext) {
117118 super();
118119 if (trace.isTraceEnabled()) {
134135 * Callback when we need to define a Closure in the JVM
135136 *
136137 */
138 @Override
137139 public void acceptClass (String name, byte[] originalBytes, byte[] wovenBytes) {
138140 try {
139141 if (shouldDump(name.replace('/', '.'), false)) {
10051007 generatedClasses = new HashMap<String, IUnwovenClassFile>();
10061008 }
10071009
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
10081034 private Unsafe unsafe;
10091035
10101036 private Unsafe getUnsafe() throws NoSuchFieldException, IllegalAccessException {
10601086 trace.exit("defineClass", clazz);
10611087 }
10621088 }
1089
10631090 }
00 /*******************************************************************************
1 * Copyright (c) 2005 Contributors.
1 * Copyright (c) 2005,2018 Contributors.
22 * All rights reserved.
33 * This program and the accompanying materials are made available
44 * under the terms of the Eclipse Public License v1.0
55 * which accompanies this distribution and is available at
66 * http://eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Alexandre Vasseur initial implementation
107 *******************************************************************************/
118 package org.aspectj.weaver.loadtime;
129
1714 * further use on Java 1.3 / 1.4
1815 *
1916 * @author Alexandre Vasseur
17 * @author Andy Clement
2018 */
2119 public interface ClassPreProcessor {
2220
2523 */
2624 void initialize();
2725
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 */
3726 byte[] preProcess(String className, byte[] bytes, ClassLoader classLoader, ProtectionDomain protectionDomain);
27
28 void prepareForRedefinition(ClassLoader loader, String className);
3829 }
00 /*******************************************************************************
1 * Copyright (c) 2005 Contributors.
1 * Copyright (c) 2005,2018 Contributors.
22 * All rights reserved.
33 * This program and the accompanying materials are made available
44 * under the terms of the Eclipse Public License v1.0
55 * which accompanies this distribution and is available at
66 * http://eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Alexandre Vasseur initial implementation
107 *******************************************************************************/
118 package org.aspectj.weaver.loadtime;
129
1714 /**
1815 * Java 1.5 adapter for class pre processor
1916 *
20 * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
17 * @author Alexandre Vasseur
18 * @author Andy Clement
2119 */
2220 public class ClassPreProcessorAgentAdapter implements ClassFileTransformer {
2321
24 /**
25 * Concrete preprocessor.
26 */
27 private static ClassPreProcessor s_preProcessor;
22 private static ClassPreProcessor classPreProcessor;
2823
2924 static {
3025 try {
31 s_preProcessor = new Aj();
32 s_preProcessor.initialize();
26 classPreProcessor = new Aj();
27 classPreProcessor.initialize();
3328 } catch (Exception e) {
3429 throw new ExceptionInInitializerError("could not initialize JSR163 preprocessor due to: " + e.toString());
3530 }
4540 * @param bytes the incoming bytes (before weaving)
4641 * @return the woven bytes
4742 */
43 @Override
4844 public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain,
4945 byte[] bytes) throws IllegalClassFormatException {
5046 if (classBeingRedefined != null) {
5147 System.err.println("INFO: (Enh120375): AspectJ attempting reweave of '" + className + "'");
48 classPreProcessor.prepareForRedefinition(loader, className);
5249 }
53 return s_preProcessor.preProcess(className, bytes, loader, protectionDomain);
50 return classPreProcessor.preProcess(className, bytes, loader, protectionDomain);
5451 }
5552 }
806806 buildConfig.setTargetAspectjRuntimeLevel(Constants.RUNTIME_LEVEL_12);
807807 } else if (arg.endsWith(":1.5")) {
808808 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");
811813 }
812814 } else if (arg.equals("-timers")) {
813815 buildConfig.setTiming(true);
2020 import java.util.ArrayList;
2121 import java.util.LinkedList;
2222 import java.util.List;
23 import java.util.StringTokenizer;
2324
2425 public class ConfigParser {
2526 Location location;
4243 LinkedList<Arg> args = new LinkedList<Arg>();
4344 for (int i = 0; i < argsArray.length; i++) {
4445 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 }
4561 }
4662 parseArgs(args);
4763 }
137153 if (sourceFile.getName().charAt(0) == '*') {
138154 if (sourceFile.getName().equals("*.java")) {
139155 addFiles(sourceFile.getParentFile(), new FileFilter() {
156 @Override
140157 public boolean accept(File f) {
141158 return f != null && f.getName().endsWith(".java");
142159 }
143160 });
144161 } else if (sourceFile.getName().equals("*.aj")) {
145162 addFiles(sourceFile.getParentFile(), new FileFilter() {
163 @Override
146164 public boolean accept(File f) {
147165 return f != null && f.getName().endsWith(".aj");
148166 }
286304 private Location location;
287305 private String value;
288306
307 @Override
289308 public String toString() {
290309 return "Arg[location="+location+" value="+value+"]";
291310 }
319338
320339 public abstract int getLine();
321340
341 @Override
322342 public abstract String toString();
323343 }
324344
331351 this.file = file;
332352 }
333353
354 @Override
334355 public File getFile() {
335356 return file;
336357 }
337358
359 @Override
338360 public File getDirectory() {
339361 return file.getParentFile();
340362 }
341363
364 @Override
342365 public int getLine() {
343366 return line;
344367 }
345368
369 @Override
346370 public String toString() {
347371 return file.getPath() + ":" + line;
348372 }
349373 }
350374
351375 static class CommandLineLocation extends Location {
376 @Override
352377 public File getFile() {
353378 return new File(System.getProperty("user.dir"));
354379 }
355380
381 @Override
356382 public File getDirectory() {
357383 return new File(System.getProperty("user.dir"));
358384 }
359385
386 @Override
360387 public int getLine() {
361388 return -1;
362389 }
363390
391 @Override
364392 public String toString() {
365393 return "command-line";
366394 }
33 The -Xlintfile:lint.properties allows fine-grained control. In tools.jar, see
44 org/aspectj/weaver/XlintDefault.properties for the default behavior and a template to copy.
55 ### AspectJ-specific messages
6 compiler.name = AspectJ Compiler 1.9.0.RC3
6 compiler.name = AspectJ Compiler 1.9.0
77 compiler.version = Eclipse Compiler #1bfc7b4202e874c(Feb2018), 3.14
88 compiler.copyright =
99
2121
2222 public final static String RUNTIME_LEVEL_12 = "1.2";
2323 public final static String RUNTIME_LEVEL_15 = "1.5";
24 public final static String RUNTIME_LEVEL_19 = "1.9";
2425
2526 // Default for 1.5.0
2627 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 }
109109 private boolean incrementalCompileCouldFollow = false;
110110
111111 /** 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
114115 /** Flags for the new joinpoints that are 'optional': -Xjoinpoints:arrayconstruction -Xjoinpoints:synchronization */
115116 private boolean optionalJoinpoint_ArrayConstruction = false;
116117 private boolean optionalJoinpoint_Synchronization = false;
201202 /**
202203 * Dump processing when a fatal error occurs
203204 */
205 @Override
204206 public void accept(Dump.IVisitor visitor) {
205207 // visitor.visitObject("Extra configuration:");
206208 // visitor.visitList(extraConfiguration.);
981983 }
982984
983985 public void setTargetAspectjRuntimeLevel(String s) {
984 targetAspectjRuntimeLevel = s;
986 targetAspectjRuntimeLevel = RuntimeVersion.getVersionFor(s);
985987 }
986988
987989 public void setOptionalJoinpoints(String jps) {
10041006 return optionalJoinpoint_Synchronization;
10051007 }
10061008
1007 public String getTargetAspectjRuntimeLevel() {
1009 public RuntimeVersion getTargetAspectjRuntimeLevel() {
10081010 return targetAspectjRuntimeLevel;
10091011 }
10101012
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?
10131014 public boolean isTargettingAspectJRuntime12() {
10141015 boolean b = false; // pr116679
10151016 if (!isInJava5Mode()) {
10161017 b = true;
10171018 } 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 }
10211021 return b;
10221022 }
10231023
7171 this.isExactDeclaringTypePattern = (declaringType instanceof ExactTypePattern);
7272 }
7373
74 @Override
7475 public SignaturePattern resolveBindings(IScope scope, Bindings bindings) {
7576 if (returnType != null) {
7677 returnType = returnType.resolveBindings(scope, bindings, false, false);
289290 * return a copy of this signature pattern in which every type variable reference is replaced by the corresponding entry in the
290291 * map.
291292 */
293 @Override
292294 public SignaturePattern parameterizeWith(Map<String, UnresolvedType> typeVariableMap, World w) {
293295 SignaturePattern ret = new SignaturePattern(kind, modifiers, returnType.parameterizeWith(typeVariableMap, w), declaringType
294296 .parameterizeWith(typeVariableMap, w), name, parameterTypes.parameterizeWith(typeVariableMap, w), throwsPattern
297299 return ret;
298300 }
299301
302 @Override
300303 public boolean matches(Member joinPointSignature, World world, boolean allowBridgeMethods) {
301304 // fail (or succeed!) fast tests...
302305 if (joinPointSignature == null) {
627630
628631 if (!parameterTypes.matches(resolvedParameters, TypePattern.STATIC, parameterAnnotationTypes).alwaysTrue()) {
629632 // 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()) {
631634 return FuzzyBoolean.MAYBE;
632635 // It could STILL be a match based on the erasure of the parameter types??
633636 // to be determined via test cases...
967970 return annotationPattern;
968971 }
969972
973 @Override
970974 public boolean isStarAnnotation() {
971975 return annotationPattern == AnnotationTypePattern.ANY;
972976 }
980984 return isExactDeclaringTypePattern;
981985 }
982986
987 @Override
983988 public boolean isMatchOnAnyName() {
984989 return getName().isAny();
985990 }
986991
992 @Override
987993 public List<ExactTypePattern> getExactDeclaringTypes() {
988994 if (declaringType instanceof ExactTypePattern) {
989995 List<ExactTypePattern> l = new ArrayList<ExactTypePattern>();
9941000 }
9951001 }
9961002
1003 @Override
9971004 public boolean couldEverMatch(ResolvedType type) {
9981005 return declaringType.matches(type, TypePattern.STATIC).maybeTrue();
9991006 }
00 /* *******************************************************************
11 * Copyright (c) 1999-2001 Xerox Corporation,
2 * 2002 Palo Alto Research Center, Incorporated (PARC).
2 * 2002-2018 Palo Alto Research Center, Incorporated (PARC), Contributors
33 * All rights reserved.
44 * This program and the accompanying materials are made available
55 * under the terms of the Eclipse Public License v1.0
77 * http://www.eclipse.org/legal/epl-v10.html
88 *
99 * Contributors:
10 * Xerox/PARC initial implementation
10 * Xerox/PARC initial implementation
1111 * 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>
1314 * ******************************************************************/
1415
1516 package org.aspectj.runtime.reflect;
3738 ClassLoader lookupClassLoader;
3839 String filename;
3940 int count;
41
42 private static final Class[] NO_TYPES = new Class[0];
43 private static final String[] NO_STRINGS = new String[0];
4044
4145 static Hashtable prims = new Hashtable();
4246 static {
5458 static Class makeClass(String s, ClassLoader loader) {
5559 if (s.equals("*"))
5660 return null;
57 Class ret = (Class) prims.get(s);
61 Class ret = (Class)prims.get(s);
5862 if (ret != null)
5963 return ret;
6064 try {
112116 Signature sig = this.makeMethodSig(modifiers, methodName, declaringType, paramTypes, paramNames, "", returnType);
113117 return new JoinPointImpl.StaticPartImpl(count++, kind, sig, makeSourceLoc(l, -1));
114118 }
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 // ---
115218
116219 public JoinPoint.StaticPart makeSJP(String kind, Signature sig, SourceLocation loc) {
117220 return new JoinPointImpl.StaticPartImpl(count++, kind, sig, loc);
180283 ret.setLookupClassLoader(lookupClassLoader);
181284 return ret;
182285 }
183
286
184287 public MethodSignature makeMethodSig(String modifiers, String methodName, String declaringType, String paramTypes,
185288 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) {
186295 int modifiersAsInt = Integer.parseInt(modifiers, 16);
187
188 Class declaringTypeClass = makeClass(declaringType, lookupClassLoader);
189296
190297 StringTokenizer st = new StringTokenizer(paramTypes, ":");
191298 int numParams = st.countTokens();
215322
216323 public MethodSignature makeMethodSig(int modifiers, String name, Class declaringType, Class[] parameterTypes,
217324 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);
220327 ret.setLookupClassLoader(lookupClassLoader);
221328 return ret;
222329 }
722722
723723 // / The repository interface methods
724724
725 @Override
725726 public JavaClass findClass(String className) {
726727 return lookupJavaClass(classPath, className);
727728 }
728729
730 @Override
729731 public JavaClass loadClass(String className) throws ClassNotFoundException {
730732 return lookupJavaClass(classPath, className);
731733 }
732734
735 @Override
733736 public void storeClass(JavaClass clazz) {
734737 // doesn't need to do anything
735738 }
736739
740 @Override
737741 public void removeClass(JavaClass clazz) {
738742 throw new RuntimeException("Not implemented");
739743 }
740744
745 @Override
741746 public JavaClass loadClass(Class clazz) throws ClassNotFoundException {
742747 throw new RuntimeException("Not implemented");
743748 }
744749
750 @Override
745751 public void clear() {
746752 delegate.clear();
747753 // throw new RuntimeException("Not implemented");
12901296
12911297 }
12921298
1299 @Override
12931300 public TypeMap getTypeMap() {
12941301 return typeMap;
12951302 }
12961303
1304 @Override
12971305 public boolean isLoadtimeWeaving() {
12981306 return false;
12991307 }
13051313 typeDelegateResolvers.add(typeDelegateResolver);
13061314 }
13071315
1316 @Override
13081317 public void classWriteEvent(char[][] compoundName) {
13091318 typeMap.classWriteEvent(new String(CharOperation.concatWith(compoundName, '.')));
13101319 }
5252 import org.aspectj.bridge.IMessage;
5353 import org.aspectj.bridge.ISourceLocation;
5454 import org.aspectj.bridge.SourceLocation;
55 import org.aspectj.util.LangUtil;
5655 import org.aspectj.weaver.AjAttribute;
5756 import org.aspectj.weaver.AjAttribute.WeaverState;
5857 import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
5958 import org.aspectj.weaver.BCException;
6059 import org.aspectj.weaver.Member;
60 import org.aspectj.weaver.MemberKind;
6161 import org.aspectj.weaver.NameMangler;
6262 import org.aspectj.weaver.ResolvedMember;
6363 import org.aspectj.weaver.ResolvedType;
64 import org.aspectj.weaver.RuntimeVersion;
6465 import org.aspectj.weaver.Shadow;
6566 import org.aspectj.weaver.SignatureUtils;
6667 import org.aspectj.weaver.TypeVariable;
7879 * Aspect.
7980 */
8081 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
81121
82122 private static final int ACC_SYNTHETIC = 0x1000;
83123
12311271
12321272 List<Map.Entry<BcelShadow, Field>> entries = new ArrayList<Map.Entry<BcelShadow, Field>>(tjpFields.entrySet());
12331273 Collections.sort(entries, new Comparator<Map.Entry<BcelShadow, Field>>() {
1274 @Override
12341275 public int compare(Map.Entry<BcelShadow, Field> a, Map.Entry<BcelShadow, Field> b) {
12351276 return (a.getValue()).getName().compareTo((b.getValue()).getName());
12361277 }
12521293 }
12531294
12541295 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 }
12551300 boolean fastSJP = false;
12561301 // avoid fast SJP if it is for an enclosing joinpoint
12571302 boolean isFastSJPAvailable = shadow.getWorld().isTargettingRuntime1_6_10()
12731318 String signatureMakerName = SignatureUtils.getSignatureMakerName(sig);
12741319 ObjectType signatureType = new ObjectType(SignatureUtils.getSignatureType(sig));
12751320 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
12791322 list.append(InstructionFactory.PUSH(cp, SignatureUtils.getSignatureString(sig, shadow.getWorld())));
12801323 list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, Type.STRINGARRAY1,
12811324 Constants.INVOKEVIRTUAL));
13691412 list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, Type.STRINGARRAY2,
13701413 Constants.INVOKEVIRTUAL));
13711414 } else {
1415 // TODO looks like this block is unused code
13721416 list.append(InstructionFactory.PUSH(cp, SignatureUtils.getSignatureString(sig, shadow.getWorld())));
13731417 list.append(fact.createInvoke(factoryType.getClassName(), signatureMakerName, signatureType, Type.STRINGARRAY1,
13741418 Constants.INVOKEVIRTUAL));
14141458 }
14151459 }
14161460
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 }
14211663
14221664 protected String makeString(int i) {
14231665 return Integer.toString(i, 16); // ??? expensive
14351677 } else {
14361678 return t.getName();
14371679 }
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);
14381698 }
14391699 }
14401700
00 /* *******************************************************************
1 * Copyright (c) 2008 Contributors
1 * Copyright (c) 2008, 2018 Contributors
22 * All rights reserved.
33 * This program and the accompanying materials are made available
44 * under the terms of the Eclipse Public License v1.0
1414 import org.aspectj.weaver.UnresolvedType;
1515 import org.aspectj.weaver.World;
1616
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;
1822
1923 /**
2024 * 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
7882
7983
8084 // Implementation of getCommonSuperClass() that avoids Class.forName()
85 @Override
8186 protected String getCommonSuperClass(final String type1, final String type2) {
8287
8388 ResolvedType resolvedType1 = world.resolve(UnresolvedType.forName(type1.replace('/', '.')));
96101 } else {
97102 do {
98103 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 }
99112 if (resolvedType1.isParameterizedOrGenericType()) {
100113 resolvedType1 = resolvedType1.getRawType();
101114 }