You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

World.java 68KB

15 years ago
13 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
15 years ago
14 years ago
14 years ago
15 years ago
15 years ago
15 years ago
12 years ago
15 years ago
12 years ago
15 years ago
12 years ago
15 years ago
12 years ago
15 years ago
15 years ago
12 years ago
15 years ago
14 years ago
14 years ago
15 years ago
12 years ago
15 years ago
15 years ago
14 years ago
13 years ago
14 years ago
15 years ago
13 years ago
15 years ago
14 years ago
14 years ago
14 years ago
15 years ago
15 years ago
14 years ago
15 years ago
13 years ago
13 years ago
15 years ago
15 years ago
15 years ago
14 years ago
14 years ago
15 years ago
13 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
15 years ago
15 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
14 years ago
15 years ago
12 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
14 years ago
15 years ago
15 years ago
14 years ago
13 years ago
15 years ago
14 years ago
15 years ago
15 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
14 years ago
15 years ago
15 years ago
15 years ago
15 years ago
14 years ago
14 years ago
13 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
15 years ago
15 years ago
15 years ago
14 years ago
15 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
15 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
15 years ago
15 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
12 years ago
15 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
15 years ago
14 years ago
15 years ago
15 years ago
14 years ago
14 years ago
14 years ago
14 years ago
15 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
15 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
15 years ago
14 years ago
13 years ago
15 years ago
15 years ago
15 years ago
14 years ago
14 years ago
15 years ago
14 years ago
13 years ago
14 years ago
13 years ago
13 years ago
14 years ago
15 years ago
15 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
15 years ago
14 years ago
14 years ago
15 years ago
14 years ago
14 years ago
15 years ago
15 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
15 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * 2005 Contributors
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors:
  11. * PARC initial implementation
  12. * Adrian Colyer, Andy Clement, overhaul for generics, Abraham Nevado
  13. * ******************************************************************/
  14. package org.aspectj.weaver;
  15. import java.lang.ref.Reference;
  16. import java.lang.ref.ReferenceQueue;
  17. import java.lang.ref.SoftReference;
  18. import java.lang.ref.WeakReference;
  19. import java.util.ArrayList;
  20. import java.util.Collections;
  21. import java.util.HashMap;
  22. import java.util.HashSet;
  23. import java.util.Iterator;
  24. import java.util.List;
  25. import java.util.Map;
  26. import java.util.Properties;
  27. import java.util.Set;
  28. import java.util.WeakHashMap;
  29. import org.aspectj.bridge.IMessage;
  30. import org.aspectj.bridge.IMessage.Kind;
  31. import org.aspectj.bridge.IMessageHandler;
  32. import org.aspectj.bridge.ISourceLocation;
  33. import org.aspectj.bridge.Message;
  34. import org.aspectj.bridge.MessageUtil;
  35. import org.aspectj.bridge.context.PinpointingMessageHandler;
  36. import org.aspectj.util.IStructureModel;
  37. import org.aspectj.weaver.ResolvedType.Primitive;
  38. import org.aspectj.weaver.UnresolvedType.TypeKind;
  39. import org.aspectj.weaver.patterns.Declare;
  40. import org.aspectj.weaver.patterns.DeclareAnnotation;
  41. import org.aspectj.weaver.patterns.DeclareParents;
  42. import org.aspectj.weaver.patterns.DeclarePrecedence;
  43. import org.aspectj.weaver.patterns.DeclareSoft;
  44. import org.aspectj.weaver.patterns.DeclareTypeErrorOrWarning;
  45. import org.aspectj.weaver.patterns.Pointcut;
  46. import org.aspectj.weaver.patterns.TypePattern;
  47. import org.aspectj.weaver.tools.PointcutDesignatorHandler;
  48. import org.aspectj.weaver.tools.Trace;
  49. import org.aspectj.weaver.tools.TraceFactory;
  50. /**
  51. * A World is a collection of known types and crosscutting members.
  52. */
  53. public abstract class World implements Dump.INode {
  54. /** handler for any messages produced during resolution etc. */
  55. private IMessageHandler messageHandler = IMessageHandler.SYSTEM_ERR;
  56. /** handler for cross-reference information produced during the weaving process */
  57. private ICrossReferenceHandler xrefHandler = null;
  58. /** Currently 'active' scope in which to lookup (resolve) typevariable references */
  59. private TypeVariableDeclaringElement typeVariableLookupScope;
  60. /** The heart of the world, a map from type signatures to resolved types */
  61. protected TypeMap typeMap = new TypeMap(this);
  62. /** New pointcut designators this world supports */
  63. private Set<PointcutDesignatorHandler> pointcutDesignators;
  64. // see pr145963
  65. /** Should we create the hierarchy for binary classes and aspects */
  66. public static boolean createInjarHierarchy = true;
  67. /** Calculator for working out aspect precedence */
  68. private final AspectPrecedenceCalculator precedenceCalculator;
  69. /** All of the type and shadow mungers known to us */
  70. private final CrosscuttingMembersSet crosscuttingMembersSet = new CrosscuttingMembersSet(this);
  71. /** The structure model for the compilation */
  72. private IStructureModel model = null;
  73. /** for processing Xlint messages */
  74. private Lint lint = new Lint(this);
  75. /** XnoInline option setting passed down to weaver */
  76. private boolean XnoInline;
  77. /** XlazyTjp option setting passed down to weaver */
  78. private boolean XlazyTjp;
  79. /** XhasMember option setting passed down to weaver */
  80. private boolean XhasMember = false;
  81. /** Xpinpoint controls whether we put out developer info showing the source of messages */
  82. private boolean Xpinpoint = false;
  83. /** When behaving in a Java 5 way autoboxing is considered */
  84. private boolean behaveInJava5Way = false;
  85. /** Should timing information be reported (as info messages)? */
  86. private boolean timing = false;
  87. private boolean timingPeriodically = true;
  88. /** Determines if this world could be used for multiple compiles */
  89. private boolean incrementalCompileCouldFollow = false;
  90. /** The level of the aspectjrt.jar the code we generate needs to run on */
  91. private String targetAspectjRuntimeLevel = Constants.RUNTIME_LEVEL_DEFAULT;
  92. /** Flags for the new joinpoints that are 'optional': -Xjoinpoints:arrayconstruction -Xjoinpoints:synchronization */
  93. private boolean optionalJoinpoint_ArrayConstruction = false;
  94. private boolean optionalJoinpoint_Synchronization = false;
  95. private boolean addSerialVerUID = false;
  96. private Properties extraConfiguration = null;
  97. private boolean checkedAdvancedConfiguration = false;
  98. private boolean synchronizationPointcutsInUse = false;
  99. // Xset'table options
  100. private boolean runMinimalMemory = false;
  101. private boolean transientTjpFields = false;
  102. private boolean runMinimalMemorySet = false;
  103. private boolean shouldPipelineCompilation = true;
  104. private boolean shouldGenerateStackMaps = false;
  105. protected boolean bcelRepositoryCaching = xsetBCEL_REPOSITORY_CACHING_DEFAULT.equalsIgnoreCase("true");
  106. private boolean fastMethodPacking = false;
  107. private int itdVersion = 2; // defaults to 2nd generation itds
  108. // Minimal Model controls whether model entities that are not involved in relationships are deleted post-build
  109. private boolean minimalModel = true;
  110. private boolean useFinal = true;
  111. private boolean targettingRuntime1_6_10 = false;
  112. private boolean completeBinaryTypes = false;
  113. private boolean overWeaving = false;
  114. private static boolean systemPropertyOverWeaving = false;
  115. public boolean forDEBUG_structuralChangesCode = false;
  116. public boolean forDEBUG_bridgingCode = false;
  117. public boolean optimizedMatching = true;
  118. public boolean generateNewLvts = true;
  119. protected long timersPerJoinpoint = 25000;
  120. protected long timersPerType = 250;
  121. public int infoMessagesEnabled = 0; // 0=uninitialized, 1=no, 2=yes
  122. private static Trace trace = TraceFactory.getTraceFactory().getTrace(World.class);
  123. private boolean errorThreshold;
  124. private boolean warningThreshold;
  125. /**
  126. * A list of RuntimeExceptions containing full stack information for every type we couldn't find.
  127. */
  128. private List<RuntimeException> dumpState_cantFindTypeExceptions = null;
  129. static {
  130. try {
  131. String value = System.getProperty("aspectj.overweaving", "false");
  132. if (value.equalsIgnoreCase("true")) {
  133. System.out.println("ASPECTJ: aspectj.overweaving=true: overweaving switched ON");
  134. systemPropertyOverWeaving = true;
  135. }
  136. } catch (Throwable t) {
  137. System.err.println("ASPECTJ: Unable to read system properties");
  138. t.printStackTrace();
  139. }
  140. }
  141. public final Primitive BYTE = new Primitive("B", 1, 0);
  142. public final Primitive CHAR = new Primitive("C", 1, 1);
  143. public final Primitive DOUBLE = new Primitive("D", 2, 2);
  144. public final Primitive FLOAT = new Primitive("F", 1, 3);
  145. public final Primitive INT = new Primitive("I", 1, 4);
  146. public final Primitive LONG = new Primitive("J", 2, 5);
  147. public final Primitive SHORT = new Primitive("S", 1, 6);
  148. public final Primitive BOOLEAN = new Primitive("Z", 1, 7);
  149. public final Primitive VOID = new Primitive("V", 0, 8);
  150. /**
  151. * Insert the primitives
  152. */
  153. protected World() {
  154. super();
  155. // Dump.registerNode(this.getClass(), this);
  156. typeMap.put("B", BYTE);
  157. typeMap.put("S", SHORT);
  158. typeMap.put("I", INT);
  159. typeMap.put("J", LONG);
  160. typeMap.put("F", FLOAT);
  161. typeMap.put("D", DOUBLE);
  162. typeMap.put("C", CHAR);
  163. typeMap.put("Z", BOOLEAN);
  164. typeMap.put("V", VOID);
  165. precedenceCalculator = new AspectPrecedenceCalculator(this);
  166. }
  167. /**
  168. * Dump processing when a fatal error occurs
  169. */
  170. public void accept(Dump.IVisitor visitor) {
  171. // visitor.visitObject("Extra configuration:");
  172. // visitor.visitList(extraConfiguration.);
  173. visitor.visitObject("Shadow mungers:");
  174. visitor.visitList(crosscuttingMembersSet.getShadowMungers());
  175. visitor.visitObject("Type mungers:");
  176. visitor.visitList(crosscuttingMembersSet.getTypeMungers());
  177. visitor.visitObject("Late Type mungers:");
  178. visitor.visitList(crosscuttingMembersSet.getLateTypeMungers());
  179. if (dumpState_cantFindTypeExceptions != null) {
  180. visitor.visitObject("Cant find type problems:");
  181. visitor.visitList(dumpState_cantFindTypeExceptions);
  182. dumpState_cantFindTypeExceptions = null;
  183. }
  184. }
  185. // ==========================================================================
  186. // T Y P E R E S O L U T I O N
  187. // ==========================================================================
  188. /**
  189. * Resolve a type that we require to be present in the world
  190. */
  191. public ResolvedType resolve(UnresolvedType ty) {
  192. return resolve(ty, false);
  193. }
  194. /**
  195. * Attempt to resolve a type - the source location gives you some context in which resolution is taking place. In the case of an
  196. * error where we can't find the type - we can then at least report why (source location) we were trying to resolve it.
  197. */
  198. public ResolvedType resolve(UnresolvedType ty, ISourceLocation isl) {
  199. ResolvedType ret = resolve(ty, true);
  200. if (ResolvedType.isMissing(ty)) {
  201. // IMessage msg = null;
  202. getLint().cantFindType.signal(WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE, ty.getName()), isl);
  203. // if (isl!=null) {
  204. // msg = MessageUtil.error(WeaverMessages.format(WeaverMessages.
  205. // CANT_FIND_TYPE,ty.getName()),isl);
  206. // } else {
  207. // msg = MessageUtil.error(WeaverMessages.format(WeaverMessages.
  208. // CANT_FIND_TYPE,ty.getName()));
  209. // }
  210. // messageHandler.handleMessage(msg);
  211. }
  212. return ret;
  213. }
  214. /**
  215. * Convenience method for resolving an array of unresolved types in one hit. Useful for e.g. resolving type parameters in
  216. * signatures.
  217. */
  218. public ResolvedType[] resolve(UnresolvedType[] types) {
  219. if (types == null) {
  220. return ResolvedType.NONE;
  221. }
  222. ResolvedType[] ret = new ResolvedType[types.length];
  223. for (int i = 0; i < types.length; i++) {
  224. ret[i] = resolve(types[i]);
  225. }
  226. return ret;
  227. }
  228. /**
  229. * Resolve a type. This the hub of type resolution. The resolved type is added to the type map by signature.
  230. */
  231. public ResolvedType resolve(UnresolvedType ty, boolean allowMissing) {
  232. // special resolution processing for already resolved types.
  233. if (ty instanceof ResolvedType) {
  234. ResolvedType rty = (ResolvedType) ty;
  235. rty = resolve(rty);
  236. // A TypeVariableReferenceType may look like it is resolved (it extends ResolvedType) but the internal
  237. // type variable may not yet have been resolved
  238. if (!rty.isTypeVariableReference() || ((TypeVariableReferenceType) rty).isTypeVariableResolved()) {
  239. return rty;
  240. }
  241. }
  242. // dispatch back to the type variable reference to resolve its
  243. // constituent parts don't do this for other unresolved types otherwise
  244. // you'll end up in a
  245. // loop
  246. if (ty.isTypeVariableReference()) {
  247. return ty.resolve(this);
  248. }
  249. // if we've already got a resolved type for the signature, just return
  250. // it
  251. // after updating the world
  252. String signature = ty.getSignature();
  253. ResolvedType ret = typeMap.get(signature);
  254. if (ret != null) {
  255. ret.world = this; // Set the world for the RTX
  256. return ret;
  257. } else if (signature.equals("?") || signature.equals("*")) {
  258. // might be a problem here, not sure '?' should make it to here as a
  259. // signature, the
  260. // proper signature for wildcard '?' is '*'
  261. // fault in generic wildcard, can't be done earlier because of init
  262. // issues
  263. // TODO ought to be shared single instance representing this
  264. ResolvedType something = getWildcard();
  265. typeMap.put("?", something);
  266. return something;
  267. }
  268. // no existing resolved type, create one
  269. synchronized (buildingTypeLock) {
  270. if (ty.isArray()) {
  271. ResolvedType componentType = resolve(ty.getComponentType(), allowMissing);
  272. ret = new ArrayReferenceType(signature, "[" + componentType.getErasureSignature(), this, componentType);
  273. } else {
  274. ret = resolveToReferenceType(ty, allowMissing);
  275. if (!allowMissing && ret.isMissing()) {
  276. ret = handleRequiredMissingTypeDuringResolution(ty);
  277. }
  278. if (completeBinaryTypes) {
  279. completeBinaryType(ret);
  280. }
  281. }
  282. }
  283. // Pulling in the type may have already put the right entry in the map
  284. ResolvedType result = typeMap.get(signature);
  285. if (result == null && !ret.isMissing()) {
  286. ret = ensureRawTypeIfNecessary(ret);
  287. typeMap.put(signature, ret);
  288. return ret;
  289. }
  290. if (result == null) {
  291. return ret;
  292. } else {
  293. return result;
  294. }
  295. }
  296. private Object buildingTypeLock = new Object();
  297. // Only need one representation of '?' in a world - can be shared
  298. private BoundedReferenceType wildcard;
  299. private BoundedReferenceType getWildcard() {
  300. if (wildcard == null) {
  301. wildcard = new BoundedReferenceType(this);
  302. }
  303. return wildcard;
  304. }
  305. /**
  306. * Called when a type is resolved - enables its type hierarchy to be finished off before we proceed
  307. */
  308. protected void completeBinaryType(ResolvedType ret) {
  309. }
  310. /**
  311. * Return true if the classloader relating to this world is definetly the one that will define the specified class. Return false
  312. * otherwise or we don't know for certain.
  313. */
  314. public boolean isLocallyDefined(String classname) {
  315. return false;
  316. }
  317. /**
  318. * We tried to resolve a type and couldn't find it...
  319. */
  320. private ResolvedType handleRequiredMissingTypeDuringResolution(UnresolvedType ty) {
  321. // defer the message until someone asks a question of the type that we
  322. // can't answer
  323. // just from the signature.
  324. // MessageUtil.error(messageHandler,
  325. // WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE,ty.getName()));
  326. if (dumpState_cantFindTypeExceptions == null) {
  327. dumpState_cantFindTypeExceptions = new ArrayList<RuntimeException>();
  328. }
  329. if (dumpState_cantFindTypeExceptions.size() < 100) { // limit growth
  330. dumpState_cantFindTypeExceptions.add(new RuntimeException("Can't find type " + ty.getName()));
  331. }
  332. return new MissingResolvedTypeWithKnownSignature(ty.getSignature(), this);
  333. }
  334. /**
  335. * Some TypeFactory operations create resolved types directly, but these won't be in the typeMap - this resolution process puts
  336. * them there. Resolved types are also told their world which is needed for the special autoboxing resolved types.
  337. */
  338. public ResolvedType resolve(ResolvedType ty) {
  339. if (ty.isTypeVariableReference()) {
  340. return ty; // until type variables have proper sigs...
  341. }
  342. ResolvedType resolved = typeMap.get(ty.getSignature());
  343. if (resolved == null) {
  344. resolved = ensureRawTypeIfNecessary(ty);
  345. typeMap.put(ty.getSignature(), resolved);
  346. resolved = ty;
  347. }
  348. resolved.world = this;
  349. return resolved;
  350. }
  351. /**
  352. * When the world is operating in 1.5 mode, the TypeMap should only contain RAW types and never directly generic types. The RAW
  353. * type will contain a reference to the generic type.
  354. *
  355. * @param type a possibly generic type for which the raw needs creating as it is not currently in the world
  356. * @return a type suitable for putting into the world
  357. */
  358. private ResolvedType ensureRawTypeIfNecessary(ResolvedType type) {
  359. if (!isInJava5Mode() || type.isRawType()) {
  360. return type;
  361. }
  362. // Key requirement here is if it is generic, create a RAW entry to be put in the map that points to it
  363. if (type instanceof ReferenceType && ((ReferenceType) type).getDelegate() != null && type.isGenericType()) {
  364. ReferenceType rawType = new ReferenceType(type.getSignature(), this);
  365. rawType.typeKind = UnresolvedType.TypeKind.RAW;
  366. ReferenceTypeDelegate delegate = ((ReferenceType) type).getDelegate();
  367. rawType.setDelegate(delegate);
  368. rawType.setGenericType((ReferenceType) type);
  369. return rawType;
  370. }
  371. // probably parameterized...
  372. return type;
  373. }
  374. /**
  375. * Convenience method for finding a type by name and resolving it in one step.
  376. */
  377. public ResolvedType resolve(String name) {
  378. // trace.enter("resolve", this, new Object[] {name});
  379. ResolvedType ret = resolve(UnresolvedType.forName(name));
  380. // trace.exit("resolve", ret);
  381. return ret;
  382. }
  383. public ReferenceType resolveToReferenceType(String name) {
  384. return (ReferenceType) resolve(name);
  385. }
  386. public ResolvedType resolve(String name, boolean allowMissing) {
  387. return resolve(UnresolvedType.forName(name), allowMissing);
  388. }
  389. /**
  390. * Resolve to a ReferenceType - simple, raw, parameterized, or generic. Raw, parameterized, and generic versions of a type share
  391. * a delegate.
  392. */
  393. private final ResolvedType resolveToReferenceType(UnresolvedType ty, boolean allowMissing) {
  394. if (ty.isParameterizedType()) {
  395. // ======= parameterized types ================
  396. ResolvedType rt = resolveGenericTypeFor(ty, allowMissing);
  397. if (rt.isMissing()) {
  398. return rt;
  399. }
  400. ReferenceType genericType = (ReferenceType) rt;
  401. ReferenceType parameterizedType = TypeFactory.createParameterizedType(genericType, ty.typeParameters, this);
  402. return parameterizedType;
  403. } else if (ty.isGenericType()) {
  404. // ======= generic types ======================
  405. ResolvedType rt = resolveGenericTypeFor(ty, false);
  406. if (rt.isMissing()) {
  407. return rt;
  408. }
  409. ReferenceType genericType = (ReferenceType) rt;
  410. return genericType;
  411. } else if (ty.isGenericWildcard()) {
  412. // ======= generic wildcard types =============
  413. return resolveGenericWildcardFor((WildcardedUnresolvedType) ty);
  414. } else {
  415. // ======= simple and raw types ===============
  416. String erasedSignature = ty.getErasureSignature();
  417. ReferenceType simpleOrRawType = new ReferenceType(erasedSignature, this);
  418. if (ty.needsModifiableDelegate()) {
  419. simpleOrRawType.setNeedsModifiableDelegate(true);
  420. }
  421. ReferenceTypeDelegate delegate = resolveDelegate(simpleOrRawType);
  422. if (delegate == null) {
  423. return new MissingResolvedTypeWithKnownSignature(ty.getSignature(), erasedSignature, this);
  424. }
  425. if (delegate.isGeneric() && behaveInJava5Way) {
  426. // ======== raw type ===========
  427. simpleOrRawType.typeKind = TypeKind.RAW;
  428. if (simpleOrRawType.hasNewInterfaces()) { // debug 375777
  429. throw new IllegalStateException(
  430. "Simple type promoted forced to raw, but it had new interfaces/superclass. Type is "
  431. + simpleOrRawType.getName());
  432. }
  433. ReferenceType genericType = makeGenericTypeFrom(delegate, simpleOrRawType);
  434. simpleOrRawType.setDelegate(delegate);
  435. genericType.setDelegate(delegate);
  436. simpleOrRawType.setGenericType(genericType);
  437. return simpleOrRawType;
  438. } else {
  439. // ======== simple type =========
  440. simpleOrRawType.setDelegate(delegate);
  441. return simpleOrRawType;
  442. }
  443. }
  444. }
  445. /**
  446. * Attempt to resolve a type that should be a generic type.
  447. */
  448. public ResolvedType resolveGenericTypeFor(UnresolvedType anUnresolvedType, boolean allowMissing) {
  449. // Look up the raw type by signature
  450. String rawSignature = anUnresolvedType.getRawType().getSignature();
  451. ResolvedType rawType = typeMap.get(rawSignature);
  452. if (rawType == null) {
  453. rawType = resolve(UnresolvedType.forSignature(rawSignature), allowMissing);
  454. typeMap.put(rawSignature, rawType);
  455. }
  456. if (rawType.isMissing()) {
  457. return rawType;
  458. }
  459. // Does the raw type know its generic form? (It will if we created the
  460. // raw type from a source type, it won't if its been created just
  461. // through
  462. // being referenced, e.g. java.util.List
  463. ResolvedType genericType = rawType.getGenericType();
  464. // There is a special case to consider here (testGenericsBang_pr95993
  465. // highlights it)
  466. // You may have an unresolvedType for a parameterized type but it
  467. // is backed by a simple type rather than a generic type. This occurs
  468. // for
  469. // inner types of generic types that inherit their enclosing types
  470. // type variables.
  471. if (rawType.isSimpleType() && (anUnresolvedType.typeParameters == null || anUnresolvedType.typeParameters.length == 0)) {
  472. rawType.world = this;
  473. return rawType;
  474. }
  475. if (genericType != null) {
  476. genericType.world = this;
  477. return genericType;
  478. } else {
  479. // Fault in the generic that underpins the raw type ;)
  480. ReferenceTypeDelegate delegate = resolveDelegate((ReferenceType) rawType);
  481. ReferenceType genericRefType = makeGenericTypeFrom(delegate, ((ReferenceType) rawType));
  482. ((ReferenceType) rawType).setGenericType(genericRefType);
  483. genericRefType.setDelegate(delegate);
  484. ((ReferenceType) rawType).setDelegate(delegate);
  485. return genericRefType;
  486. }
  487. }
  488. private ReferenceType makeGenericTypeFrom(ReferenceTypeDelegate delegate, ReferenceType rawType) {
  489. String genericSig = delegate.getDeclaredGenericSignature();
  490. if (genericSig != null) {
  491. return new ReferenceType(UnresolvedType.forGenericTypeSignature(rawType.getSignature(),
  492. delegate.getDeclaredGenericSignature()), this);
  493. } else {
  494. return new ReferenceType(UnresolvedType.forGenericTypeVariables(rawType.getSignature(), delegate.getTypeVariables()),
  495. this);
  496. }
  497. }
  498. /**
  499. * Go from an unresolved generic wildcard (represented by UnresolvedType) to a resolved version (BoundedReferenceType).
  500. */
  501. private ReferenceType resolveGenericWildcardFor(WildcardedUnresolvedType aType) {
  502. BoundedReferenceType ret = null;
  503. // FIXME asc doesnt take account of additional interface bounds (e.g. ? super R & Serializable - can you do that?)
  504. if (aType.isExtends()) {
  505. ResolvedType resolvedUpperBound = resolve(aType.getUpperBound());
  506. if (resolvedUpperBound.isMissing()) {
  507. return getWildcard();
  508. }
  509. ret = new BoundedReferenceType((ReferenceType)resolvedUpperBound, true, this);
  510. } else if (aType.isSuper()) {
  511. ResolvedType resolvedLowerBound = resolve(aType.getLowerBound());
  512. if (resolvedLowerBound.isMissing()) {
  513. return getWildcard();
  514. }
  515. ret = new BoundedReferenceType((ReferenceType)resolvedLowerBound, false, this);
  516. } else {
  517. // must be ? on its own!
  518. ret = getWildcard();
  519. }
  520. return ret;
  521. }
  522. /**
  523. * Find the ReferenceTypeDelegate behind this reference type so that it can fulfill its contract.
  524. */
  525. protected abstract ReferenceTypeDelegate resolveDelegate(ReferenceType ty);
  526. /**
  527. * Special resolution for "core" types like OBJECT. These are resolved just like any other type, but if they are not found it is
  528. * more serious and we issue an error message immediately.
  529. */
  530. // OPTIMIZE streamline path for core types? They are just simple types,
  531. // could look straight in the typemap?
  532. public ResolvedType getCoreType(UnresolvedType tx) {
  533. ResolvedType coreTy = resolve(tx, true);
  534. if (coreTy.isMissing()) {
  535. MessageUtil.error(messageHandler, WeaverMessages.format(WeaverMessages.CANT_FIND_CORE_TYPE, tx.getName()));
  536. }
  537. return coreTy;
  538. }
  539. /**
  540. * Lookup a type by signature, if not found then build one and put it in the map.
  541. */
  542. public ReferenceType lookupOrCreateName(UnresolvedType ty) {
  543. String signature = ty.getSignature();
  544. ReferenceType ret = lookupBySignature(signature);
  545. if (ret == null) {
  546. ret = ReferenceType.fromTypeX(ty, this);
  547. typeMap.put(signature, ret);
  548. }
  549. return ret;
  550. }
  551. /**
  552. * Lookup a reference type in the world by its signature. Returns null if not found.
  553. */
  554. public ReferenceType lookupBySignature(String signature) {
  555. return (ReferenceType) typeMap.get(signature);
  556. }
  557. // ==========================================================================
  558. // ===
  559. // T Y P E R E S O L U T I O N -- E N D
  560. // ==========================================================================
  561. // ===
  562. /**
  563. * Member resolution is achieved by resolving the declaring type and then looking up the member in the resolved declaring type.
  564. */
  565. public ResolvedMember resolve(Member member) {
  566. ResolvedType declaring = member.getDeclaringType().resolve(this);
  567. if (declaring.isRawType()) {
  568. declaring = declaring.getGenericType();
  569. }
  570. ResolvedMember ret;
  571. if (member.getKind() == Member.FIELD) {
  572. ret = declaring.lookupField(member);
  573. } else {
  574. ret = declaring.lookupMethod(member);
  575. }
  576. if (ret != null) {
  577. return ret;
  578. }
  579. return declaring.lookupSyntheticMember(member);
  580. }
  581. private boolean allLintIgnored = false;
  582. public void setAllLintIgnored() {
  583. allLintIgnored = true;
  584. }
  585. public boolean areAllLintIgnored() {
  586. return allLintIgnored;
  587. }
  588. public abstract IWeavingSupport getWeavingSupport();
  589. /**
  590. * Create an advice shadow munger from the given advice attribute
  591. */
  592. // public abstract Advice createAdviceMunger(AjAttribute.AdviceAttribute
  593. // attribute, Pointcut pointcut, Member signature);
  594. /**
  595. * Create an advice shadow munger for the given advice kind
  596. */
  597. public final Advice createAdviceMunger(AdviceKind kind, Pointcut p, Member signature, int extraParameterFlags,
  598. IHasSourceLocation loc, ResolvedType declaringAspect) {
  599. AjAttribute.AdviceAttribute attribute = new AjAttribute.AdviceAttribute(kind, p, extraParameterFlags, loc.getStart(),
  600. loc.getEnd(), loc.getSourceContext());
  601. return getWeavingSupport().createAdviceMunger(attribute, p, signature, declaringAspect);
  602. }
  603. /**
  604. * Same signature as org.aspectj.util.PartialOrder.PartialComparable.compareTo
  605. */
  606. public int compareByPrecedence(ResolvedType aspect1, ResolvedType aspect2) {
  607. return precedenceCalculator.compareByPrecedence(aspect1, aspect2);
  608. }
  609. public Integer getPrecedenceIfAny(ResolvedType aspect1, ResolvedType aspect2) {
  610. return precedenceCalculator.getPrecedenceIfAny(aspect1, aspect2);
  611. }
  612. /**
  613. * compares by precedence with the additional rule that a super-aspect is sorted before its sub-aspects
  614. */
  615. public int compareByPrecedenceAndHierarchy(ResolvedType aspect1, ResolvedType aspect2) {
  616. return precedenceCalculator.compareByPrecedenceAndHierarchy(aspect1, aspect2);
  617. }
  618. // simple property getter and setters
  619. // ===========================================================
  620. /**
  621. * Nobody should hold onto a copy of this message handler, or setMessageHandler won't work right.
  622. */
  623. public IMessageHandler getMessageHandler() {
  624. return messageHandler;
  625. }
  626. public void setMessageHandler(IMessageHandler messageHandler) {
  627. if (this.isInPinpointMode()) {
  628. this.messageHandler = new PinpointingMessageHandler(messageHandler);
  629. } else {
  630. this.messageHandler = messageHandler;
  631. }
  632. }
  633. /**
  634. * convenenience method for creating and issuing messages via the message handler - if you supply two locations you will get two
  635. * messages.
  636. */
  637. public void showMessage(Kind kind, String message, ISourceLocation loc1, ISourceLocation loc2) {
  638. if (loc1 != null) {
  639. messageHandler.handleMessage(new Message(message, kind, null, loc1));
  640. if (loc2 != null) {
  641. messageHandler.handleMessage(new Message(message, kind, null, loc2));
  642. }
  643. } else {
  644. messageHandler.handleMessage(new Message(message, kind, null, loc2));
  645. }
  646. }
  647. public void setCrossReferenceHandler(ICrossReferenceHandler xrefHandler) {
  648. this.xrefHandler = xrefHandler;
  649. }
  650. /**
  651. * Get the cross-reference handler for the world, may be null.
  652. */
  653. public ICrossReferenceHandler getCrossReferenceHandler() {
  654. return xrefHandler;
  655. }
  656. public void setTypeVariableLookupScope(TypeVariableDeclaringElement scope) {
  657. typeVariableLookupScope = scope;
  658. }
  659. public TypeVariableDeclaringElement getTypeVariableLookupScope() {
  660. return typeVariableLookupScope;
  661. }
  662. public List<DeclareParents> getDeclareParents() {
  663. return crosscuttingMembersSet.getDeclareParents();
  664. }
  665. public List<DeclareAnnotation> getDeclareAnnotationOnTypes() {
  666. return crosscuttingMembersSet.getDeclareAnnotationOnTypes();
  667. }
  668. public List<DeclareAnnotation> getDeclareAnnotationOnFields() {
  669. return crosscuttingMembersSet.getDeclareAnnotationOnFields();
  670. }
  671. public List<DeclareAnnotation> getDeclareAnnotationOnMethods() {
  672. return crosscuttingMembersSet.getDeclareAnnotationOnMethods();
  673. }
  674. public List<DeclareTypeErrorOrWarning> getDeclareTypeEows() {
  675. return crosscuttingMembersSet.getDeclareTypeEows();
  676. }
  677. public List<DeclareSoft> getDeclareSoft() {
  678. return crosscuttingMembersSet.getDeclareSofts();
  679. }
  680. public CrosscuttingMembersSet getCrosscuttingMembersSet() {
  681. return crosscuttingMembersSet;
  682. }
  683. public IStructureModel getModel() {
  684. return model;
  685. }
  686. public void setModel(IStructureModel model) {
  687. this.model = model;
  688. }
  689. public Lint getLint() {
  690. return lint;
  691. }
  692. public void setLint(Lint lint) {
  693. this.lint = lint;
  694. }
  695. public boolean isXnoInline() {
  696. return XnoInline;
  697. }
  698. public void setXnoInline(boolean xnoInline) {
  699. XnoInline = xnoInline;
  700. }
  701. public boolean isXlazyTjp() {
  702. return XlazyTjp;
  703. }
  704. public void setXlazyTjp(boolean b) {
  705. XlazyTjp = b;
  706. }
  707. public boolean isHasMemberSupportEnabled() {
  708. return XhasMember;
  709. }
  710. public void setXHasMemberSupportEnabled(boolean b) {
  711. XhasMember = b;
  712. }
  713. public boolean isInPinpointMode() {
  714. return Xpinpoint;
  715. }
  716. public void setPinpointMode(boolean b) {
  717. Xpinpoint = b;
  718. }
  719. public boolean useFinal() {
  720. return useFinal;
  721. }
  722. public boolean isMinimalModel() {
  723. ensureAdvancedConfigurationProcessed();
  724. return minimalModel;
  725. }
  726. public boolean isTargettingRuntime1_6_10() {
  727. ensureAdvancedConfigurationProcessed();
  728. return targettingRuntime1_6_10;
  729. }
  730. public void setBehaveInJava5Way(boolean b) {
  731. behaveInJava5Way = b;
  732. }
  733. /**
  734. * Set the timing option (whether to collect timing info), this will also need INFO messages turned on for the message handler
  735. * being used. The reportPeriodically flag should be set to false under AJDT so numbers just come out at the end.
  736. */
  737. public void setTiming(boolean timersOn, boolean reportPeriodically) {
  738. timing = timersOn;
  739. timingPeriodically = reportPeriodically;
  740. }
  741. /**
  742. * Set the error and warning threashold which can be taken from CompilerOptions (see bug 129282)
  743. *
  744. * @param errorThreshold
  745. * @param warningThreshold
  746. */
  747. public void setErrorAndWarningThreshold(boolean errorThreshold, boolean warningThreshold) {
  748. this.errorThreshold = errorThreshold;
  749. this.warningThreshold = warningThreshold;
  750. }
  751. /**
  752. * @return true if ignoring the UnusedDeclaredThrownException and false if this compiler option is set to error or warning
  753. */
  754. public boolean isIgnoringUnusedDeclaredThrownException() {
  755. // the 0x800000 is CompilerOptions.UnusedDeclaredThrownException
  756. // which is ASTNode.bit24
  757. return errorThreshold||warningThreshold;
  758. // if ((errorThreshold & 0x800000) != 0 || (warningThreshold & 0x800000) != 0) {
  759. // return false;
  760. // }
  761. // return true;
  762. }
  763. public void performExtraConfiguration(String config) {
  764. if (config == null) {
  765. return;
  766. }
  767. // Bunch of name value pairs to split
  768. extraConfiguration = new Properties();
  769. int pos = -1;
  770. while ((pos = config.indexOf(",")) != -1) {
  771. String nvpair = config.substring(0, pos);
  772. int pos2 = nvpair.indexOf("=");
  773. if (pos2 != -1) {
  774. String n = nvpair.substring(0, pos2);
  775. String v = nvpair.substring(pos2 + 1);
  776. extraConfiguration.setProperty(n, v);
  777. }
  778. config = config.substring(pos + 1);
  779. }
  780. if (config.length() > 0) {
  781. int pos2 = config.indexOf("=");
  782. if (pos2 != -1) {
  783. String n = config.substring(0, pos2);
  784. String v = config.substring(pos2 + 1);
  785. extraConfiguration.setProperty(n, v);
  786. }
  787. }
  788. ensureAdvancedConfigurationProcessed();
  789. }
  790. public boolean areInfoMessagesEnabled() {
  791. if (infoMessagesEnabled == 0) {
  792. infoMessagesEnabled = (messageHandler.isIgnoring(IMessage.INFO) ? 1 : 2);
  793. }
  794. return infoMessagesEnabled == 2;
  795. }
  796. /**
  797. * may return null
  798. */
  799. public Properties getExtraConfiguration() {
  800. return extraConfiguration;
  801. }
  802. public final static String xsetAVOID_FINAL = "avoidFinal"; // default true
  803. public final static String xsetWEAVE_JAVA_PACKAGES = "weaveJavaPackages"; // default
  804. // false
  805. // -
  806. // controls
  807. // LTW
  808. public final static String xsetWEAVE_JAVAX_PACKAGES = "weaveJavaxPackages"; // default
  809. // false
  810. // -
  811. // controls
  812. // LTW
  813. public final static String xsetCAPTURE_ALL_CONTEXT = "captureAllContext"; // default
  814. // false
  815. public final static String xsetRUN_MINIMAL_MEMORY = "runMinimalMemory"; // default
  816. // true
  817. public final static String xsetDEBUG_STRUCTURAL_CHANGES_CODE = "debugStructuralChangesCode"; // default
  818. // false
  819. public final static String xsetDEBUG_BRIDGING = "debugBridging"; // default
  820. // false
  821. public final static String xsetTRANSIENT_TJP_FIELDS = "makeTjpFieldsTransient"; // default false
  822. public final static String xsetBCEL_REPOSITORY_CACHING = "bcelRepositoryCaching";
  823. public final static String xsetPIPELINE_COMPILATION = "pipelineCompilation";
  824. public final static String xsetGENERATE_STACKMAPS = "generateStackMaps";
  825. public final static String xsetPIPELINE_COMPILATION_DEFAULT = "true";
  826. public final static String xsetCOMPLETE_BINARY_TYPES = "completeBinaryTypes";
  827. public final static String xsetCOMPLETE_BINARY_TYPES_DEFAULT = "false";
  828. public final static String xsetTYPE_DEMOTION = "typeDemotion";
  829. public final static String xsetTYPE_DEMOTION_DEBUG = "typeDemotionDebug";
  830. public final static String xsetTYPE_REFS = "useWeakTypeRefs";
  831. public final static String xsetBCEL_REPOSITORY_CACHING_DEFAULT = "true";
  832. public final static String xsetFAST_PACK_METHODS = "fastPackMethods"; // default true
  833. public final static String xsetOVERWEAVING = "overWeaving";
  834. public final static String xsetOPTIMIZED_MATCHING = "optimizedMatching";
  835. public final static String xsetTIMERS_PER_JOINPOINT = "timersPerJoinpoint";
  836. public final static String xsetTIMERS_PER_FASTMATCH_CALL = "timersPerFastMatchCall";
  837. public final static String xsetITD_VERSION = "itdVersion";
  838. public final static String xsetITD_VERSION_ORIGINAL = "1";
  839. public final static String xsetITD_VERSION_2NDGEN = "2";
  840. public final static String xsetITD_VERSION_DEFAULT = xsetITD_VERSION_2NDGEN;
  841. public final static String xsetMINIMAL_MODEL = "minimalModel";
  842. public final static String xsetTARGETING_RUNTIME_1610 = "targetRuntime1_6_10";
  843. // This option allows you to prevent AspectJ adding local variable tables - some tools (e.g. dex) may
  844. // not like what gets created because even though it is valid, the bytecode they are processing has
  845. // unexpected quirks that mean the table entries are violated in the code. See issue:
  846. // https://bugs.eclipse.org/bugs/show_bug.cgi?id=470658
  847. public final static String xsetGENERATE_NEW_LVTS="generateNewLocalVariableTables";
  848. public boolean isInJava5Mode() {
  849. return behaveInJava5Way;
  850. }
  851. public boolean isTimingEnabled() {
  852. return timing;
  853. }
  854. public void setTargetAspectjRuntimeLevel(String s) {
  855. targetAspectjRuntimeLevel = s;
  856. }
  857. public void setOptionalJoinpoints(String jps) {
  858. if (jps == null) {
  859. return;
  860. }
  861. if (jps.indexOf("arrayconstruction") != -1) {
  862. optionalJoinpoint_ArrayConstruction = true;
  863. }
  864. if (jps.indexOf("synchronization") != -1) {
  865. optionalJoinpoint_Synchronization = true;
  866. }
  867. }
  868. public boolean isJoinpointArrayConstructionEnabled() {
  869. return optionalJoinpoint_ArrayConstruction;
  870. }
  871. public boolean isJoinpointSynchronizationEnabled() {
  872. return optionalJoinpoint_Synchronization;
  873. }
  874. public String getTargetAspectjRuntimeLevel() {
  875. return targetAspectjRuntimeLevel;
  876. }
  877. // OPTIMIZE are users falling foul of not supplying -1.5 and so targetting
  878. // the old runtime?
  879. public boolean isTargettingAspectJRuntime12() {
  880. boolean b = false; // pr116679
  881. if (!isInJava5Mode()) {
  882. b = true;
  883. } else {
  884. b = getTargetAspectjRuntimeLevel().equals(org.aspectj.weaver.Constants.RUNTIME_LEVEL_12);
  885. }
  886. // System.err.println("Asked if targetting runtime 1.2 , returning: "+b);
  887. return b;
  888. }
  889. /*
  890. * Map of types in the world, can have 'references' to expendable ones which can be garbage collected to recover memory. An
  891. * expendable type is a reference type that is not exposed to the weaver (ie just pulled in for type resolution purposes).
  892. * Generic types have their raw form added to the map, which has a pointer to the underlying generic.
  893. */
  894. public static class TypeMap {
  895. // Strategy for entries in the expendable map
  896. public final static int DONT_USE_REFS = 0; // Hang around forever
  897. public final static int USE_WEAK_REFS = 1; // Collected asap
  898. public final static int USE_SOFT_REFS = 2; // Collected when short on memory
  899. public List<String> addedSinceLastDemote;
  900. public List<String> writtenClasses;
  901. private static boolean debug = false;
  902. public static boolean useExpendableMap = true; // configurable for reliable testing
  903. private boolean demotionSystemActive;
  904. private boolean debugDemotion = false;
  905. public int policy = USE_WEAK_REFS;
  906. // Map of types that never get thrown away
  907. final Map<String, ResolvedType> tMap = new HashMap<String, ResolvedType>();
  908. // Map of types that may be ejected from the cache if we need space
  909. final Map<String, Reference<ResolvedType>> expendableMap = Collections
  910. .synchronizedMap(new WeakHashMap<String, Reference<ResolvedType>>());
  911. private final World w;
  912. // profiling tools...
  913. private boolean memoryProfiling = false;
  914. private int maxExpendableMapSize = -1;
  915. private int collectedTypes = 0;
  916. private final ReferenceQueue<ResolvedType> rq = new ReferenceQueue<ResolvedType>();
  917. TypeMap(World w) {
  918. // Demotion activated when switched on and loadtime weaving or in AJDT
  919. demotionSystemActive = w.isDemotionActive() && (w.isLoadtimeWeaving() || w.couldIncrementalCompileFollow());
  920. addedSinceLastDemote = new ArrayList<String>();
  921. writtenClasses = new ArrayList<String>();
  922. this.w = w;
  923. memoryProfiling = false;// !w.getMessageHandler().isIgnoring(Message.
  924. // INFO);
  925. }
  926. // For testing
  927. public Map<String, Reference<ResolvedType>> getExpendableMap() {
  928. return expendableMap;
  929. }
  930. // For testing
  931. public Map<String, ResolvedType> getMainMap() {
  932. return tMap;
  933. }
  934. public int demote() {
  935. return demote(false);
  936. }
  937. /**
  938. * Go through any types added during the previous file weave. If any are suitable for demotion, then put them in the
  939. * expendable map where GC can claim them at some point later. Demotion means: the type is not an aspect, the type is not
  940. * java.lang.Object, the type is not primitive and the type is not affected by type mungers in any way. Further refinements
  941. * of these conditions may allow for more demotions.
  942. *
  943. * @return number of types demoted
  944. */
  945. public int demote(boolean atEndOfCompile) {
  946. if (!demotionSystemActive) {
  947. return 0;
  948. }
  949. if (debugDemotion) {
  950. System.out.println("Demotion running " + addedSinceLastDemote);
  951. }
  952. boolean isLtw = w.isLoadtimeWeaving();
  953. int demotionCounter = 0;
  954. if (isLtw) {
  955. // Loadtime weaving demotion strategy
  956. for (String key : addedSinceLastDemote) {
  957. ResolvedType type = tMap.get(key);
  958. if (type != null && !type.isAspect() && !type.equals(UnresolvedType.OBJECT) && !type.isPrimitiveType()) {
  959. List<ConcreteTypeMunger> typeMungers = type.getInterTypeMungers();
  960. if (typeMungers == null || typeMungers.size() == 0) {
  961. tMap.remove(key);
  962. insertInExpendableMap(key, type);
  963. demotionCounter++;
  964. }
  965. }
  966. }
  967. addedSinceLastDemote.clear();
  968. } else {
  969. // Compile time demotion strategy
  970. List<String> forRemoval = new ArrayList<String>();
  971. for (String key : addedSinceLastDemote) {
  972. ResolvedType type = tMap.get(key);
  973. if (type == null) {
  974. // TODO not 100% sure why it is not there, where did it go?
  975. forRemoval.add(key);
  976. continue;
  977. }
  978. if (!writtenClasses.contains(type.getName())) { // COSTLY
  979. continue;
  980. }
  981. if (type != null && !type.isAspect() && !type.equals(UnresolvedType.OBJECT) && !type.isPrimitiveType()) {
  982. List<ConcreteTypeMunger> typeMungers = type.getInterTypeMungers();
  983. if (typeMungers == null || typeMungers.size() == 0) {
  984. /*
  985. * if (type.isNested()) { try { ReferenceType rt = (ReferenceType) w.resolve(type.getOutermostType());
  986. * if (!rt.isMissing()) { ReferenceTypeDelegate delegate = ((ReferenceType) type).getDelegate(); boolean
  987. * isWeavable = delegate == null ? false : delegate.isExposedToWeaver(); boolean hasBeenWoven = delegate
  988. * == null ? false : delegate.hasBeenWoven(); if (isWeavable && !hasBeenWoven) { // skip demotion of
  989. * this inner type for now continue; } } } catch (ClassCastException cce) { cce.printStackTrace();
  990. * System.out.println("outer of " + key + " is not a reftype? " + type.getOutermostType()); // throw new
  991. * IllegalStateException(cce); } }
  992. */
  993. ReferenceTypeDelegate delegate = ((ReferenceType) type).getDelegate();
  994. boolean isWeavable = delegate == null ? false : delegate.isExposedToWeaver();
  995. boolean hasBeenWoven = delegate == null ? false : delegate.hasBeenWoven();
  996. if (!isWeavable || hasBeenWoven) {
  997. if (debugDemotion) {
  998. System.out.println("Demoting " + key);
  999. }
  1000. forRemoval.add(key);
  1001. tMap.remove(key);
  1002. insertInExpendableMap(key, type);
  1003. demotionCounter++;
  1004. }
  1005. } else {
  1006. // no need to try this again, it will never be demoted
  1007. writtenClasses.remove(type.getName());
  1008. forRemoval.add(key);
  1009. }
  1010. } else {
  1011. writtenClasses.remove(type.getName());
  1012. // no need to try this again, it will never be demoted
  1013. forRemoval.add(key);
  1014. }
  1015. }
  1016. addedSinceLastDemote.removeAll(forRemoval);
  1017. }
  1018. if (debugDemotion) {
  1019. System.out.println("Demoted " + demotionCounter + " types. Types remaining in fixed set #" + tMap.keySet().size()
  1020. + ". addedSinceLastDemote size is " + addedSinceLastDemote.size());
  1021. System.out.println("writtenClasses.size() = " + writtenClasses.size() + ": " + writtenClasses);
  1022. }
  1023. if (atEndOfCompile) {
  1024. if (debugDemotion) {
  1025. System.out.println("Clearing writtenClasses");
  1026. }
  1027. writtenClasses.clear();
  1028. }
  1029. return demotionCounter;
  1030. }
  1031. private void insertInExpendableMap(String key, ResolvedType type) {
  1032. if (useExpendableMap) {
  1033. if (!expendableMap.containsKey(key)) {
  1034. if (policy == USE_SOFT_REFS) {
  1035. expendableMap.put(key, new SoftReference<ResolvedType>(type));
  1036. } else {
  1037. expendableMap.put(key, new WeakReference<ResolvedType>(type));
  1038. }
  1039. }
  1040. }
  1041. }
  1042. /**
  1043. * Add a new type into the map, the key is the type signature. Some types do *not* go in the map, these are ones involving
  1044. * *member* type variables. The reason is that when all you have is the signature which gives you a type variable name, you
  1045. * cannot guarantee you are using the type variable in the same way as someone previously working with a similarly named
  1046. * type variable. So, these do not go into the map: - TypeVariableReferenceType. - ParameterizedType where a member type
  1047. * variable is involved. - BoundedReferenceType when one of the bounds is a type variable.
  1048. *
  1049. * definition: "member type variables" - a tvar declared on a generic method/ctor as opposed to those you see declared on a
  1050. * generic type.
  1051. */
  1052. public ResolvedType put(String key, ResolvedType type) {
  1053. if (!type.isCacheable()) {
  1054. return type;
  1055. }
  1056. if (type.isParameterizedType() && type.isParameterizedWithTypeVariable()) {
  1057. if (debug) {
  1058. System.err
  1059. .println("Not putting a parameterized type that utilises member declared type variables into the typemap: key="
  1060. + key + " type=" + type);
  1061. }
  1062. return type;
  1063. }
  1064. if (type.isTypeVariableReference()) {
  1065. if (debug) {
  1066. System.err.println("Not putting a type variable reference type into the typemap: key=" + key + " type=" + type);
  1067. }
  1068. return type;
  1069. }
  1070. // this test should be improved - only avoid putting them in if one
  1071. // of the
  1072. // bounds is a member type variable
  1073. if (type instanceof BoundedReferenceType) {
  1074. if (debug) {
  1075. System.err.println("Not putting a bounded reference type into the typemap: key=" + key + " type=" + type);
  1076. }
  1077. return type;
  1078. }
  1079. if (type instanceof MissingResolvedTypeWithKnownSignature) {
  1080. if (debug) {
  1081. System.err.println("Not putting a missing type into the typemap: key=" + key + " type=" + type);
  1082. }
  1083. return type;
  1084. }
  1085. if ((type instanceof ReferenceType) && (((ReferenceType) type).getDelegate() == null) && w.isExpendable(type)) {
  1086. if (debug) {
  1087. System.err.println("Not putting expendable ref type with null delegate into typemap: key=" + key + " type="
  1088. + type);
  1089. }
  1090. return type;
  1091. }
  1092. // TODO should this be in as a permanent assertion?
  1093. if ((type instanceof ReferenceType) && type.getWorld().isInJava5Mode()
  1094. && (((ReferenceType) type).getDelegate() != null) && type.isGenericType()) {
  1095. throw new BCException("Attempt to add generic type to typemap " + type.toString() + " (should be raw)");
  1096. }
  1097. if (w.isExpendable(type)) {
  1098. if (useExpendableMap) {
  1099. // Dont use reference queue for tracking if not profiling...
  1100. if (policy == USE_WEAK_REFS) {
  1101. if (memoryProfiling) {
  1102. expendableMap.put(key, new WeakReference<ResolvedType>(type, rq));
  1103. } else {
  1104. expendableMap.put(key, new WeakReference<ResolvedType>(type));
  1105. }
  1106. } else if (policy == USE_SOFT_REFS) {
  1107. if (memoryProfiling) {
  1108. expendableMap.put(key, new SoftReference<ResolvedType>(type, rq));
  1109. } else {
  1110. expendableMap.put(key, new SoftReference<ResolvedType>(type));
  1111. }
  1112. // } else {
  1113. // expendableMap.put(key, type);
  1114. }
  1115. }
  1116. if (memoryProfiling && expendableMap.size() > maxExpendableMapSize) {
  1117. maxExpendableMapSize = expendableMap.size();
  1118. }
  1119. return type;
  1120. } else {
  1121. if (demotionSystemActive) {
  1122. // System.out.println("Added since last demote " + key);
  1123. addedSinceLastDemote.add(key);
  1124. }
  1125. return tMap.put(key, type);
  1126. }
  1127. }
  1128. public void report() {
  1129. if (!memoryProfiling) {
  1130. return;
  1131. }
  1132. checkq();
  1133. w.getMessageHandler().handleMessage(
  1134. MessageUtil.info("MEMORY: world expendable type map reached maximum size of #" + maxExpendableMapSize
  1135. + " entries"));
  1136. w.getMessageHandler().handleMessage(
  1137. MessageUtil.info("MEMORY: types collected through garbage collection #" + collectedTypes + " entries"));
  1138. }
  1139. public void checkq() {
  1140. if (!memoryProfiling) {
  1141. return;
  1142. }
  1143. Reference<? extends ResolvedType> r = null;
  1144. while ((r=rq.poll()) != null) {
  1145. collectedTypes++;
  1146. }
  1147. }
  1148. /**
  1149. * Lookup a type by its signature, always look in the real map before the expendable map
  1150. */
  1151. public ResolvedType get(String key) {
  1152. checkq();
  1153. ResolvedType ret = tMap.get(key);
  1154. if (ret == null) {
  1155. if (policy == USE_WEAK_REFS) {
  1156. WeakReference<ResolvedType> ref = (WeakReference<ResolvedType>) expendableMap.get(key);
  1157. if (ref != null) {
  1158. ret = ref.get();
  1159. // if (ret==null) {
  1160. // expendableMap.remove(key);
  1161. // }
  1162. }
  1163. } else if (policy == USE_SOFT_REFS) {
  1164. SoftReference<ResolvedType> ref = (SoftReference<ResolvedType>) expendableMap.get(key);
  1165. if (ref != null) {
  1166. ret = ref.get();
  1167. // if (ret==null) {
  1168. // expendableMap.remove(key);
  1169. // }
  1170. }
  1171. // } else {
  1172. // return (ResolvedType) expendableMap.get(key);
  1173. }
  1174. }
  1175. return ret;
  1176. }
  1177. /** Remove a type from the map */
  1178. public ResolvedType remove(String key) {
  1179. ResolvedType ret = tMap.remove(key);
  1180. if (ret == null) {
  1181. if (policy == USE_WEAK_REFS) {
  1182. WeakReference<ResolvedType> wref = (WeakReference<ResolvedType>) expendableMap.remove(key);
  1183. if (wref != null) {
  1184. ret = wref.get();
  1185. }
  1186. } else if (policy == USE_SOFT_REFS) {
  1187. SoftReference<ResolvedType> wref = (SoftReference<ResolvedType>) expendableMap.remove(key);
  1188. if (wref != null) {
  1189. ret = wref.get();
  1190. }
  1191. // } else {
  1192. // ret = (ResolvedType) expendableMap.remove(key);
  1193. }
  1194. }
  1195. return ret;
  1196. }
  1197. public void classWriteEvent(String classname) {
  1198. // that is a name com.Foo and not a signature Lcom/Foo; boooooooooo!
  1199. if (demotionSystemActive) {
  1200. writtenClasses.add(classname);
  1201. }
  1202. if (debugDemotion) {
  1203. System.out.println("Class write event for " + classname);
  1204. }
  1205. }
  1206. public void demote(ResolvedType type) {
  1207. String key = type.getSignature();
  1208. if (debugDemotion) {
  1209. addedSinceLastDemote.remove(key);
  1210. }
  1211. tMap.remove(key);
  1212. insertInExpendableMap(key, type);
  1213. }
  1214. // public ResolvedType[] getAllTypes() {
  1215. // List/* ResolvedType */results = new ArrayList();
  1216. //
  1217. // collectTypes(expendableMap, results);
  1218. // collectTypes(tMap, results);
  1219. // return (ResolvedType[]) results.toArray(new
  1220. // ResolvedType[results.size()]);
  1221. // }
  1222. //
  1223. // private void collectTypes(Map map, List/* ResolvedType */results) {
  1224. // for (Iterator iterator = map.keySet().iterator();
  1225. // iterator.hasNext();) {
  1226. // String key = (String) iterator.next();
  1227. // ResolvedType type = get(key);
  1228. // if (type != null)
  1229. // results.add(type);
  1230. // else
  1231. // System.err.println("null!:" + key);
  1232. // }
  1233. // }
  1234. }
  1235. /**
  1236. * This class is used to compute and store precedence relationships between aspects.
  1237. */
  1238. private static class AspectPrecedenceCalculator {
  1239. private final World world;
  1240. private final Map<PrecedenceCacheKey, Integer> cachedResults;
  1241. public AspectPrecedenceCalculator(World forSomeWorld) {
  1242. world = forSomeWorld;
  1243. cachedResults = new HashMap<PrecedenceCacheKey, Integer>();
  1244. }
  1245. /**
  1246. * Ask every declare precedence in the world to order the two aspects. If more than one declare precedence gives an
  1247. * ordering, and the orderings conflict, then that's an error.
  1248. */
  1249. public int compareByPrecedence(ResolvedType firstAspect, ResolvedType secondAspect) {
  1250. PrecedenceCacheKey key = new PrecedenceCacheKey(firstAspect, secondAspect);
  1251. if (cachedResults.containsKey(key)) {
  1252. return (cachedResults.get(key)).intValue();
  1253. } else {
  1254. int order = 0;
  1255. DeclarePrecedence orderer = null; // Records the declare
  1256. // precedence statement that
  1257. // gives the first ordering
  1258. for (Iterator<Declare> i = world.getCrosscuttingMembersSet().getDeclareDominates().iterator(); i.hasNext();) {
  1259. DeclarePrecedence d = (DeclarePrecedence) i.next();
  1260. int thisOrder = d.compare(firstAspect, secondAspect);
  1261. if (thisOrder != 0) {
  1262. if (orderer == null) {
  1263. orderer = d;
  1264. }
  1265. if (order != 0 && order != thisOrder) {
  1266. ISourceLocation[] isls = new ISourceLocation[2];
  1267. isls[0] = orderer.getSourceLocation();
  1268. isls[1] = d.getSourceLocation();
  1269. Message m = new Message("conflicting declare precedence orderings for aspects: "
  1270. + firstAspect.getName() + " and " + secondAspect.getName(), null, true, isls);
  1271. world.getMessageHandler().handleMessage(m);
  1272. } else {
  1273. order = thisOrder;
  1274. }
  1275. }
  1276. }
  1277. cachedResults.put(key, new Integer(order));
  1278. return order;
  1279. }
  1280. }
  1281. public Integer getPrecedenceIfAny(ResolvedType aspect1, ResolvedType aspect2) {
  1282. return cachedResults.get(new PrecedenceCacheKey(aspect1, aspect2));
  1283. }
  1284. public int compareByPrecedenceAndHierarchy(ResolvedType firstAspect, ResolvedType secondAspect) {
  1285. if (firstAspect.equals(secondAspect)) {
  1286. return 0;
  1287. }
  1288. int ret = compareByPrecedence(firstAspect, secondAspect);
  1289. if (ret != 0) {
  1290. return ret;
  1291. }
  1292. if (firstAspect.isAssignableFrom(secondAspect)) {
  1293. return -1;
  1294. } else if (secondAspect.isAssignableFrom(firstAspect)) {
  1295. return +1;
  1296. }
  1297. return 0;
  1298. }
  1299. private static class PrecedenceCacheKey {
  1300. public ResolvedType aspect1;
  1301. public ResolvedType aspect2;
  1302. public PrecedenceCacheKey(ResolvedType a1, ResolvedType a2) {
  1303. aspect1 = a1;
  1304. aspect2 = a2;
  1305. }
  1306. @Override
  1307. public boolean equals(Object obj) {
  1308. if (!(obj instanceof PrecedenceCacheKey)) {
  1309. return false;
  1310. }
  1311. PrecedenceCacheKey other = (PrecedenceCacheKey) obj;
  1312. return (aspect1 == other.aspect1 && aspect2 == other.aspect2);
  1313. }
  1314. @Override
  1315. public int hashCode() {
  1316. return aspect1.hashCode() + aspect2.hashCode();
  1317. }
  1318. }
  1319. }
  1320. public void validateType(UnresolvedType type) {
  1321. }
  1322. // --- with java5 we can get into a recursive mess if we aren't careful when
  1323. // resolving types (*cough* java.lang.Enum) ---
  1324. public boolean isDemotionActive() {
  1325. return true;
  1326. }
  1327. // --- this first map is for java15 delegates which may try and recursively
  1328. // access the same type variables.
  1329. // --- I would rather stash this against a reference type - but we don't
  1330. // guarantee referencetypes are unique for
  1331. // so we can't :(
  1332. private final Map<Class<?>, TypeVariable[]> workInProgress1 = new HashMap<Class<?>, TypeVariable[]>();
  1333. public TypeVariable[] getTypeVariablesCurrentlyBeingProcessed(Class<?> baseClass) {
  1334. return workInProgress1.get(baseClass);
  1335. }
  1336. public void recordTypeVariablesCurrentlyBeingProcessed(Class<?> baseClass, TypeVariable[] typeVariables) {
  1337. workInProgress1.put(baseClass, typeVariables);
  1338. }
  1339. public void forgetTypeVariablesCurrentlyBeingProcessed(Class<?> baseClass) {
  1340. workInProgress1.remove(baseClass);
  1341. }
  1342. public void setAddSerialVerUID(boolean b) {
  1343. addSerialVerUID = b;
  1344. }
  1345. public boolean isAddSerialVerUID() {
  1346. return addSerialVerUID;
  1347. }
  1348. /** be careful calling this - pr152257 */
  1349. public void flush() {
  1350. typeMap.expendableMap.clear();
  1351. }
  1352. public void ensureAdvancedConfigurationProcessed() {
  1353. // Check *once* whether the user has switched asm support off
  1354. if (!checkedAdvancedConfiguration) {
  1355. Properties p = getExtraConfiguration();
  1356. if (p != null) {
  1357. String s = p.getProperty(xsetBCEL_REPOSITORY_CACHING, xsetBCEL_REPOSITORY_CACHING_DEFAULT);
  1358. bcelRepositoryCaching = s.equalsIgnoreCase("true");
  1359. if (!bcelRepositoryCaching) {
  1360. getMessageHandler().handleMessage(
  1361. MessageUtil
  1362. .info("[bcelRepositoryCaching=false] AspectJ will not use a bcel cache for class information"));
  1363. }
  1364. // ITD Versions
  1365. // 1 is the first version in use up to AspectJ 1.6.8
  1366. // 2 is from 1.6.9 onwards
  1367. s = p.getProperty(xsetITD_VERSION, xsetITD_VERSION_DEFAULT);
  1368. if (s.equals(xsetITD_VERSION_ORIGINAL)) {
  1369. itdVersion = 1;
  1370. }
  1371. s = p.getProperty(xsetAVOID_FINAL, "false");
  1372. if (s.equalsIgnoreCase("true")) {
  1373. useFinal = false; // if avoidFinal=true, then set useFinal to false
  1374. }
  1375. s = p.getProperty(xsetMINIMAL_MODEL, "true");
  1376. if (s.equalsIgnoreCase("false")) {
  1377. minimalModel = false;
  1378. }
  1379. s = p.getProperty(xsetTARGETING_RUNTIME_1610, "false");
  1380. if (s.equalsIgnoreCase("true")) {
  1381. targettingRuntime1_6_10 = true;
  1382. }
  1383. s = p.getProperty(xsetFAST_PACK_METHODS, "true");
  1384. fastMethodPacking = s.equalsIgnoreCase("true");
  1385. s = p.getProperty(xsetPIPELINE_COMPILATION, xsetPIPELINE_COMPILATION_DEFAULT);
  1386. shouldPipelineCompilation = s.equalsIgnoreCase("true");
  1387. s = p.getProperty(xsetGENERATE_STACKMAPS, "false");
  1388. shouldGenerateStackMaps = s.equalsIgnoreCase("true");
  1389. s = p.getProperty(xsetCOMPLETE_BINARY_TYPES, xsetCOMPLETE_BINARY_TYPES_DEFAULT);
  1390. completeBinaryTypes = s.equalsIgnoreCase("true");
  1391. if (completeBinaryTypes) {
  1392. getMessageHandler().handleMessage(
  1393. MessageUtil.info("[completeBinaryTypes=true] Completion of binary types activated"));
  1394. }
  1395. s = p.getProperty(xsetTYPE_DEMOTION); // default is: ON
  1396. if (s != null) {
  1397. boolean b = typeMap.demotionSystemActive;
  1398. if (b && s.equalsIgnoreCase("false")) {
  1399. System.out.println("typeDemotion=false: type demotion switched OFF");
  1400. typeMap.demotionSystemActive = false;
  1401. } else if (!b && s.equalsIgnoreCase("true")) {
  1402. System.out.println("typeDemotion=true: type demotion switched ON");
  1403. typeMap.demotionSystemActive = true;
  1404. }
  1405. }
  1406. s = p.getProperty(xsetOVERWEAVING, "false");
  1407. if (s.equalsIgnoreCase("true")) {
  1408. overWeaving = true;
  1409. }
  1410. s = p.getProperty(xsetTYPE_DEMOTION_DEBUG, "false");
  1411. if (s.equalsIgnoreCase("true")) {
  1412. typeMap.debugDemotion = true;
  1413. }
  1414. s = p.getProperty(xsetTYPE_REFS, "true");
  1415. if (s.equalsIgnoreCase("false")) {
  1416. typeMap.policy = TypeMap.USE_SOFT_REFS;
  1417. }
  1418. runMinimalMemorySet = p.getProperty(xsetRUN_MINIMAL_MEMORY) != null;
  1419. s = p.getProperty(xsetRUN_MINIMAL_MEMORY, "false");
  1420. runMinimalMemory = s.equalsIgnoreCase("true");
  1421. // if (runMinimalMemory)
  1422. // getMessageHandler().handleMessage(MessageUtil.info(
  1423. // "[runMinimalMemory=true] Optimizing bcel processing (and cost of performance) to use less memory"
  1424. // ));
  1425. s = p.getProperty(xsetDEBUG_STRUCTURAL_CHANGES_CODE, "false");
  1426. forDEBUG_structuralChangesCode = s.equalsIgnoreCase("true");
  1427. s = p.getProperty(xsetTRANSIENT_TJP_FIELDS,"false");
  1428. transientTjpFields = s.equalsIgnoreCase("true");
  1429. s = p.getProperty(xsetDEBUG_BRIDGING, "false");
  1430. forDEBUG_bridgingCode = s.equalsIgnoreCase("true");
  1431. s = p.getProperty(xsetGENERATE_NEW_LVTS,"true");
  1432. generateNewLvts = s.equalsIgnoreCase("true");
  1433. if (!generateNewLvts) {
  1434. getMessageHandler().handleMessage(MessageUtil.info("[generateNewLvts=false] for methods without an incoming local variable table, do not generate one"));
  1435. }
  1436. s = p.getProperty(xsetOPTIMIZED_MATCHING, "true");
  1437. optimizedMatching = s.equalsIgnoreCase("true");
  1438. if (!optimizedMatching) {
  1439. getMessageHandler().handleMessage(MessageUtil.info("[optimizedMatching=false] optimized matching turned off"));
  1440. }
  1441. s = p.getProperty(xsetTIMERS_PER_JOINPOINT, "25000");
  1442. try {
  1443. timersPerJoinpoint = Integer.parseInt(s);
  1444. } catch (Exception e) {
  1445. getMessageHandler().handleMessage(MessageUtil.error("unable to process timersPerJoinpoint value of " + s));
  1446. timersPerJoinpoint = 25000;
  1447. }
  1448. s = p.getProperty(xsetTIMERS_PER_FASTMATCH_CALL, "250");
  1449. try {
  1450. timersPerType = Integer.parseInt(s);
  1451. } catch (Exception e) {
  1452. getMessageHandler().handleMessage(MessageUtil.error("unable to process timersPerType value of " + s));
  1453. timersPerType = 250;
  1454. }
  1455. }
  1456. try {
  1457. if (systemPropertyOverWeaving) {
  1458. overWeaving = true;
  1459. }
  1460. String value = null;
  1461. value = System.getProperty("aspectj.typeDemotion", "false");
  1462. if (value.equalsIgnoreCase("true")) {
  1463. System.out.println("ASPECTJ: aspectj.typeDemotion=true: type demotion switched ON");
  1464. typeMap.demotionSystemActive = true;
  1465. }
  1466. value = System.getProperty("aspectj.minimalModel", "false");
  1467. if (value.equalsIgnoreCase("true")) {
  1468. System.out.println("ASPECTJ: aspectj.minimalModel=true: minimal model switched ON");
  1469. minimalModel = true;
  1470. }
  1471. } catch (Throwable t) {
  1472. System.err.println("ASPECTJ: Unable to read system properties");
  1473. t.printStackTrace();
  1474. }
  1475. checkedAdvancedConfiguration = true;
  1476. }
  1477. }
  1478. public boolean isRunMinimalMemory() {
  1479. ensureAdvancedConfigurationProcessed();
  1480. return runMinimalMemory;
  1481. }
  1482. public boolean isTransientTjpFields() {
  1483. ensureAdvancedConfigurationProcessed();
  1484. return transientTjpFields;
  1485. }
  1486. public boolean isRunMinimalMemorySet() {
  1487. ensureAdvancedConfigurationProcessed();
  1488. return runMinimalMemorySet;
  1489. }
  1490. public boolean shouldFastPackMethods() {
  1491. ensureAdvancedConfigurationProcessed();
  1492. return fastMethodPacking;
  1493. }
  1494. public boolean shouldPipelineCompilation() {
  1495. ensureAdvancedConfigurationProcessed();
  1496. return shouldPipelineCompilation;
  1497. }
  1498. public boolean shouldGenerateStackMaps() {
  1499. ensureAdvancedConfigurationProcessed();
  1500. return shouldGenerateStackMaps;
  1501. }
  1502. public void setIncrementalCompileCouldFollow(boolean b) {
  1503. incrementalCompileCouldFollow = b;
  1504. }
  1505. public boolean couldIncrementalCompileFollow() {
  1506. return incrementalCompileCouldFollow;
  1507. }
  1508. public void setSynchronizationPointcutsInUse() {
  1509. if (trace.isTraceEnabled()) {
  1510. trace.enter("setSynchronizationPointcutsInUse", this);
  1511. }
  1512. synchronizationPointcutsInUse = true;
  1513. if (trace.isTraceEnabled()) {
  1514. trace.exit("setSynchronizationPointcutsInUse");
  1515. }
  1516. }
  1517. public boolean areSynchronizationPointcutsInUse() {
  1518. return synchronizationPointcutsInUse;
  1519. }
  1520. /**
  1521. * Register a new pointcut designator handler with the world - this can be used by any pointcut parsers attached to the world.
  1522. *
  1523. * @param designatorHandler handler for the new pointcut
  1524. */
  1525. public void registerPointcutHandler(PointcutDesignatorHandler designatorHandler) {
  1526. if (pointcutDesignators == null) {
  1527. pointcutDesignators = new HashSet<PointcutDesignatorHandler>();
  1528. }
  1529. pointcutDesignators.add(designatorHandler);
  1530. }
  1531. public Set<PointcutDesignatorHandler> getRegisteredPointcutHandlers() {
  1532. if (pointcutDesignators == null) {
  1533. return Collections.emptySet();
  1534. }
  1535. return pointcutDesignators;
  1536. }
  1537. public void reportMatch(ShadowMunger munger, Shadow shadow) {
  1538. }
  1539. public boolean isOverWeaving() {
  1540. return overWeaving;
  1541. }
  1542. public void reportCheckerMatch(Checker checker, Shadow shadow) {
  1543. }
  1544. /**
  1545. * @return true if this world has the activation and scope of application of the aspects controlled via aop.xml files
  1546. */
  1547. public boolean isXmlConfigured() {
  1548. return false;
  1549. }
  1550. public boolean isAspectIncluded(ResolvedType aspectType) {
  1551. return true;
  1552. }
  1553. /**
  1554. * Determine if the named aspect requires a particular type around in order to be useful. The type is named in the aop.xml file
  1555. * against the aspect.
  1556. *
  1557. * @return true if there is a type missing that this aspect really needed around
  1558. */
  1559. public boolean hasUnsatisfiedDependency(ResolvedType aspectType) {
  1560. return false;
  1561. }
  1562. public TypePattern getAspectScope(ResolvedType declaringType) {
  1563. return null;
  1564. }
  1565. public Map<String, ResolvedType> getFixed() {
  1566. return typeMap.tMap;
  1567. }
  1568. public Map<String, Reference<ResolvedType>> getExpendable() {
  1569. return typeMap.expendableMap;
  1570. }
  1571. /**
  1572. * Ask the type map to demote any types it can - we don't want them anchored forever.
  1573. */
  1574. public void demote() {
  1575. typeMap.demote();
  1576. }
  1577. // protected boolean isExpendable(ResolvedType type) {
  1578. // if (type.equals(UnresolvedType.OBJECT))
  1579. // return false;
  1580. // if (type == null)
  1581. // return false;
  1582. // boolean isExposed = type.isExposedToWeaver();
  1583. // boolean nullDele = (type instanceof ReferenceType) ? ((ReferenceType) type).getDelegate() != null : true;
  1584. // if (isExposed || !isExposed && nullDele)
  1585. // return false;
  1586. // return !type.isPrimitiveType();
  1587. // }
  1588. /**
  1589. * Reference types we don't intend to weave may be ejected from the cache if we need the space.
  1590. */
  1591. protected boolean isExpendable(ResolvedType type) {
  1592. return !type.equals(UnresolvedType.OBJECT) && !type.isExposedToWeaver() && !type.isPrimitiveType()
  1593. && !type.isPrimitiveArray();
  1594. }
  1595. // map from aspect > excluded types
  1596. // memory issue here?
  1597. private Map<ResolvedType, Set<ResolvedType>> exclusionMap = new HashMap<ResolvedType, Set<ResolvedType>>();
  1598. public Map<ResolvedType, Set<ResolvedType>> getExclusionMap() {
  1599. return exclusionMap;
  1600. }
  1601. private TimeCollector timeCollector = null;
  1602. /**
  1603. * Record the time spent matching a pointcut - this will accumulate over the lifetime of this world/weaver and be reported every
  1604. * 25000 join points.
  1605. */
  1606. public void record(Pointcut pointcut, long timetaken) {
  1607. if (timeCollector == null) {
  1608. ensureAdvancedConfigurationProcessed();
  1609. timeCollector = new TimeCollector(this);
  1610. }
  1611. timeCollector.record(pointcut, timetaken);
  1612. }
  1613. /**
  1614. * Record the time spent fastmatching a pointcut - this will accumulate over the lifetime of this world/weaver and be reported
  1615. * every 250 types.
  1616. */
  1617. public void recordFastMatch(Pointcut pointcut, long timetaken) {
  1618. if (timeCollector == null) {
  1619. ensureAdvancedConfigurationProcessed();
  1620. timeCollector = new TimeCollector(this);
  1621. }
  1622. timeCollector.recordFastMatch(pointcut, timetaken);
  1623. }
  1624. public void reportTimers() {
  1625. if (timeCollector != null && !timingPeriodically) {
  1626. timeCollector.report();
  1627. timeCollector = new TimeCollector(this);
  1628. }
  1629. }
  1630. private static class TimeCollector {
  1631. private World world;
  1632. long joinpointCount;
  1633. long typeCount;
  1634. long perJoinpointCount;
  1635. long perTypes;
  1636. Map<String, Long> joinpointsPerPointcut = new HashMap<String, Long>();
  1637. Map<String, Long> timePerPointcut = new HashMap<String, Long>();
  1638. Map<String, Long> fastMatchTimesPerPointcut = new HashMap<String, Long>();
  1639. Map<String, Long> fastMatchTypesPerPointcut = new HashMap<String, Long>();
  1640. TimeCollector(World world) {
  1641. this.perJoinpointCount = world.timersPerJoinpoint;
  1642. this.perTypes = world.timersPerType;
  1643. this.world = world;
  1644. this.joinpointCount = 0;
  1645. this.typeCount = 0;
  1646. this.joinpointsPerPointcut = new HashMap<String, Long>();
  1647. this.timePerPointcut = new HashMap<String, Long>();
  1648. }
  1649. public void report() {
  1650. long totalTime = 0L;
  1651. for (String p : joinpointsPerPointcut.keySet()) {
  1652. totalTime += timePerPointcut.get(p);
  1653. }
  1654. world.getMessageHandler().handleMessage(
  1655. MessageUtil.info("Pointcut matching cost (total=" + (totalTime / 1000000) + "ms for " + joinpointCount
  1656. + " joinpoint match calls):"));
  1657. for (String p : joinpointsPerPointcut.keySet()) {
  1658. StringBuffer sb = new StringBuffer();
  1659. sb.append("Time:" + (timePerPointcut.get(p) / 1000000) + "ms (jps:#" + joinpointsPerPointcut.get(p)
  1660. + ") matching against " + p);
  1661. world.getMessageHandler().handleMessage(MessageUtil.info(sb.toString()));
  1662. }
  1663. world.getMessageHandler().handleMessage(MessageUtil.info("---"));
  1664. totalTime = 0L;
  1665. for (String p : fastMatchTimesPerPointcut.keySet()) {
  1666. totalTime += fastMatchTimesPerPointcut.get(p);
  1667. }
  1668. world.getMessageHandler().handleMessage(
  1669. MessageUtil.info("Pointcut fast matching cost (total=" + (totalTime / 1000000) + "ms for " + typeCount
  1670. + " fast match calls):"));
  1671. for (String p : fastMatchTimesPerPointcut.keySet()) {
  1672. StringBuffer sb = new StringBuffer();
  1673. sb.append("Time:" + (fastMatchTimesPerPointcut.get(p) / 1000000) + "ms (types:#" + fastMatchTypesPerPointcut.get(p)
  1674. + ") fast matching against " + p);
  1675. world.getMessageHandler().handleMessage(MessageUtil.info(sb.toString()));
  1676. }
  1677. world.getMessageHandler().handleMessage(MessageUtil.info("---"));
  1678. }
  1679. void record(Pointcut pointcut, long timetakenInNs) {
  1680. joinpointCount++;
  1681. String pointcutText = pointcut.toString();
  1682. Long jpcounter = joinpointsPerPointcut.get(pointcutText);
  1683. if (jpcounter == null) {
  1684. jpcounter = 1L;
  1685. } else {
  1686. jpcounter++;
  1687. }
  1688. joinpointsPerPointcut.put(pointcutText, jpcounter);
  1689. Long time = timePerPointcut.get(pointcutText);
  1690. if (time == null) {
  1691. time = timetakenInNs;
  1692. } else {
  1693. time += timetakenInNs;
  1694. }
  1695. timePerPointcut.put(pointcutText, time);
  1696. if (world.timingPeriodically) {
  1697. if ((joinpointCount % perJoinpointCount) == 0) {
  1698. long totalTime = 0L;
  1699. for (String p : joinpointsPerPointcut.keySet()) {
  1700. totalTime += timePerPointcut.get(p);
  1701. }
  1702. world.getMessageHandler().handleMessage(
  1703. MessageUtil.info("Pointcut matching cost (total=" + (totalTime / 1000000) + "ms for " + joinpointCount
  1704. + " joinpoint match calls):"));
  1705. for (String p : joinpointsPerPointcut.keySet()) {
  1706. StringBuffer sb = new StringBuffer();
  1707. sb.append("Time:" + (timePerPointcut.get(p) / 1000000) + "ms (jps:#" + joinpointsPerPointcut.get(p)
  1708. + ") matching against " + p);
  1709. world.getMessageHandler().handleMessage(MessageUtil.info(sb.toString()));
  1710. }
  1711. world.getMessageHandler().handleMessage(MessageUtil.info("---"));
  1712. }
  1713. }
  1714. }
  1715. void recordFastMatch(Pointcut pointcut, long timetakenInNs) {
  1716. typeCount++;
  1717. String pointcutText = pointcut.toString();
  1718. Long typecounter = fastMatchTypesPerPointcut.get(pointcutText);
  1719. if (typecounter == null) {
  1720. typecounter = 1L;
  1721. } else {
  1722. typecounter++;
  1723. }
  1724. fastMatchTypesPerPointcut.put(pointcutText, typecounter);
  1725. Long time = fastMatchTimesPerPointcut.get(pointcutText);
  1726. if (time == null) {
  1727. time = timetakenInNs;
  1728. } else {
  1729. time += timetakenInNs;
  1730. }
  1731. fastMatchTimesPerPointcut.put(pointcutText, time);
  1732. if (world.timingPeriodically) {
  1733. if ((typeCount % perTypes) == 0) {
  1734. long totalTime = 0L;
  1735. for (String p : fastMatchTimesPerPointcut.keySet()) {
  1736. totalTime += fastMatchTimesPerPointcut.get(p);
  1737. }
  1738. world.getMessageHandler().handleMessage(
  1739. MessageUtil.info("Pointcut fast matching cost (total=" + (totalTime / 1000000) + "ms for " + typeCount
  1740. + " fast match calls):"));
  1741. for (String p : fastMatchTimesPerPointcut.keySet()) {
  1742. StringBuffer sb = new StringBuffer();
  1743. sb.append("Time:" + (fastMatchTimesPerPointcut.get(p) / 1000000) + "ms (types:#"
  1744. + fastMatchTypesPerPointcut.get(p) + ") fast matching against " + p);
  1745. world.getMessageHandler().handleMessage(MessageUtil.info(sb.toString()));
  1746. }
  1747. world.getMessageHandler().handleMessage(MessageUtil.info("---"));
  1748. }
  1749. }
  1750. }
  1751. }
  1752. public TypeMap getTypeMap() {
  1753. return typeMap;
  1754. }
  1755. public static void reset() {
  1756. // ResolvedType.resetPrimitives();
  1757. }
  1758. /**
  1759. * Returns the version of ITD that this world wants to create. The default is the new style (2) but in some cases where there
  1760. * might be a clash, the old style can be used. It is set through the option -Xset:itdVersion=1
  1761. *
  1762. * @return the ITD version this world wants to create - 1=oldstyle 2=new, transparent style
  1763. */
  1764. public int getItdVersion() {
  1765. return itdVersion;
  1766. }
  1767. // if not loadtime weaving then we are compile time weaving or post-compile time weaving
  1768. public abstract boolean isLoadtimeWeaving();
  1769. public void classWriteEvent(char[][] compoundName) {
  1770. // override if interested in write events
  1771. }
  1772. }