aboutsummaryrefslogtreecommitdiffstats
path: root/org.aspectj.matcher/src/org/aspectj/weaver/World.java
blob: ce52537c0614a4a24dd2f027da172ab95dc0a09e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
/* *******************************************************************
 * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
 *               2005 Contributors
 * All rights reserved. 
 * This program and the accompanying materials are made available 
 * under the terms of the Eclipse Public License v1.0 
 * which accompanies this distribution and is available at 
 * http://www.eclipse.org/legal/epl-v10.html 
 *  
 * Contributors: 
 *     PARC     initial implementation
 *     Adrian Colyer, Andy Clement, overhaul for generics, Abraham Nevado 
 * ******************************************************************/

package org.aspectj.weaver;

import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.WeakHashMap;

import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.IMessage.Kind;
import org.aspectj.bridge.IMessageHandler;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.bridge.Message;
import org.aspectj.bridge.MessageUtil;
import org.aspectj.bridge.context.PinpointingMessageHandler;
import org.aspectj.util.IStructureModel;
import org.aspectj.weaver.UnresolvedType.TypeKind;
import org.aspectj.weaver.patterns.Declare;
import org.aspectj.weaver.patterns.DeclareAnnotation;
import org.aspectj.weaver.patterns.DeclareParents;
import org.aspectj.weaver.patterns.DeclarePrecedence;
import org.aspectj.weaver.patterns.DeclareSoft;
import org.aspectj.weaver.patterns.DeclareTypeErrorOrWarning;
import org.aspectj.weaver.patterns.Pointcut;
import org.aspectj.weaver.patterns.TypePattern;
import org.aspectj.weaver.tools.PointcutDesignatorHandler;
import org.aspectj.weaver.tools.Trace;
import org.aspectj.weaver.tools.TraceFactory;

/**
 * A World is a collection of known types and crosscutting members.
 */
public abstract class World implements Dump.INode {
	/** handler for any messages produced during resolution etc. */
	private IMessageHandler messageHandler = IMessageHandler.SYSTEM_ERR;

	/**
	 * handler for cross-reference information produced during the weaving process
	 */
	private ICrossReferenceHandler xrefHandler = null;

	/**
	 * Currently 'active' scope in which to lookup (resolve) typevariable references
	 */
	private TypeVariableDeclaringElement typeVariableLookupScope;

	/** The heart of the world, a map from type signatures to resolved types */
	protected TypeMap typeMap = new TypeMap(this); // Signature to ResolvedType

	/** New pointcut designators this world supports */
	private Set<PointcutDesignatorHandler> pointcutDesignators;

	// see pr145963
	/** Should we create the hierarchy for binary classes and aspects */
	public static boolean createInjarHierarchy = true;

	/** Calculator for working out aspect precedence */
	private final AspectPrecedenceCalculator precedenceCalculator;

	/** All of the type and shadow mungers known to us */
	private final CrosscuttingMembersSet crosscuttingMembersSet = new CrosscuttingMembersSet(this);

	/** The structure model for the compilation */
	private IStructureModel model = null;

	/** for processing Xlint messages */
	private Lint lint = new Lint(this);

	/** XnoInline option setting passed down to weaver */
	private boolean XnoInline;

	/** XlazyTjp option setting passed down to weaver */
	private boolean XlazyTjp;

	/** XhasMember option setting passed down to weaver */
	private boolean XhasMember = false;

	/**
	 * Xpinpoint controls whether we put out developer info showing the source of messages
	 */
	private boolean Xpinpoint = false;

	/** When behaving in a Java 5 way autoboxing is considered */
	private boolean behaveInJava5Way = false;

	/** Should timing information be reported (as info messages)? */
	private boolean timing = false;
	private boolean timingPeriodically = true;

	/** Determines if this world could be used for multiple compiles */
	private boolean incrementalCompileCouldFollow = false;

	/** The level of the aspectjrt.jar the code we generate needs to run on */
	private String targetAspectjRuntimeLevel = Constants.RUNTIME_LEVEL_DEFAULT;

	/** Flags for the new joinpoints that are 'optional' */
	private boolean optionalJoinpoint_ArrayConstruction = false; // Command line
	// flag:
	// "-Xjoinpoints:arrayconstruction"
	private boolean optionalJoinpoint_Synchronization = false; // Command line
	// flag:
	// "-Xjoinpoints:synchronization"

	private boolean addSerialVerUID = false;

	private Properties extraConfiguration = null;
	private boolean checkedAdvancedConfiguration = false;
	private boolean synchronizationPointcutsInUse = false;
	// Xset'table options
	private boolean runMinimalMemory = false;
	private boolean runMinimalMemorySet = false;
	private boolean shouldPipelineCompilation = true;
	private boolean shouldGenerateStackMaps = false;
	protected boolean bcelRepositoryCaching = xsetBCEL_REPOSITORY_CACHING_DEFAULT.equalsIgnoreCase("true");
	private boolean fastMethodPacking = false;
	private int itdVersion = 2; // defaults to 2nd generation itds

	// Minimal Model controls whether model entities that are not involved in relationships are deleted post-build
	private boolean minimalModel = false;
	private boolean targettingRuntime1_6_10 = false;

	private boolean completeBinaryTypes = false;
	private boolean overWeaving = false;
	public boolean forDEBUG_structuralChangesCode = false;
	public boolean forDEBUG_bridgingCode = false;
	public boolean optimizedMatching = true;
	protected long timersPerJoinpoint = 25000;
	protected long timersPerType = 250;

	public int infoMessagesEnabled = 0; // 0=uninitialized, 1=no, 2=yes

	private static Trace trace = TraceFactory.getTraceFactory().getTrace(World.class);

	private long errorThreshold;
	private long warningThreshold;

	/**
	 * A list of RuntimeExceptions containing full stack information for every type we couldn't find.
	 */
	private List<RuntimeException> dumpState_cantFindTypeExceptions = null;

	/**
	 * Play God. On the first day, God created the primitive types and put them in the type map.
	 */
	protected World() {
		super();
		if (trace.isTraceEnabled()) {
			trace.enter("<init>", this);
		}
		// Dump.registerNode(this.getClass(), this);
		typeMap.put("B", ResolvedType.BYTE);
		typeMap.put("S", ResolvedType.SHORT);
		typeMap.put("I", ResolvedType.INT);
		typeMap.put("J", ResolvedType.LONG);
		typeMap.put("F", ResolvedType.FLOAT);
		typeMap.put("D", ResolvedType.DOUBLE);
		typeMap.put("C", ResolvedType.CHAR);
		typeMap.put("Z", ResolvedType.BOOLEAN);
		typeMap.put("V", ResolvedType.VOID);
		precedenceCalculator = new AspectPrecedenceCalculator(this);
		if (trace.isTraceEnabled()) {
			trace.exit("<init>");
		}
	}

	/**
	 * Dump processing when a fatal error occurs
	 */
	public void accept(Dump.IVisitor visitor) {
		// visitor.visitObject("Extra configuration:");
		// visitor.visitList(extraConfiguration.);
		visitor.visitObject("Shadow mungers:");
		visitor.visitList(crosscuttingMembersSet.getShadowMungers());
		visitor.visitObject("Type mungers:");
		visitor.visitList(crosscuttingMembersSet.getTypeMungers());
		visitor.visitObject("Late Type mungers:");
		visitor.visitList(crosscuttingMembersSet.getLateTypeMungers());
		if (dumpState_cantFindTypeExceptions != null) {
			visitor.visitObject("Cant find type problems:");
			visitor.visitList(dumpState_cantFindTypeExceptions);
			dumpState_cantFindTypeExceptions = null;
		}
	}

	// ==========================================================================
	// ===
	// T Y P E R E S O L U T I O N
	// ==========================================================================
	// ===

	/**
	 * Resolve a type that we require to be present in the world
	 */
	public ResolvedType resolve(UnresolvedType ty) {
		return resolve(ty, false);
	}

	/**
	 * Attempt to resolve a type - the source location gives you some context in which resolution is taking place. In the case of an
	 * error where we can't find the type - we can then at least report why (source location) we were trying to resolve it.
	 */
	public ResolvedType resolve(UnresolvedType ty, ISourceLocation isl) {
		ResolvedType ret = resolve(ty, true);
		if (ResolvedType.isMissing(ty)) {
			// IMessage msg = null;
			getLint().cantFindType.signal(WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE, ty.getName()), isl);
			// if (isl!=null) {
			// msg = MessageUtil.error(WeaverMessages.format(WeaverMessages.
			// CANT_FIND_TYPE,ty.getName()),isl);
			// } else {
			// msg = MessageUtil.error(WeaverMessages.format(WeaverMessages.
			// CANT_FIND_TYPE,ty.getName()));
			// }
			// messageHandler.handleMessage(msg);
		}
		return ret;
	}

	/**
	 * Convenience method for resolving an array of unresolved types in one hit. Useful for e.g. resolving type parameters in
	 * signatures.
	 */
	public ResolvedType[] resolve(UnresolvedType[] types) {
		if (types == null) {
			return ResolvedType.NONE;
		}

		ResolvedType[] ret = new ResolvedType[types.length];
		for (int i = 0; i < types.length; i++) {
			ret[i] = resolve(types[i]);
		}
		return ret;
	}

	/**
	 * Resolve a type. This the hub of type resolution. The resolved type is added to the type map by signature.
	 */
	public ResolvedType resolve(UnresolvedType ty, boolean allowMissing) {

		// special resolution processing for already resolved types.
		if (ty instanceof ResolvedType) {
			ResolvedType rty = (ResolvedType) ty;
			rty = resolve(rty);
			return rty;
		}

		// dispatch back to the type variable reference to resolve its
		// constituent parts
		// don't do this for other unresolved types otherwise you'll end up in a
		// loop
		if (ty.isTypeVariableReference()) {
			return ty.resolve(this);
		}

		// if we've already got a resolved type for the signature, just return
		// it
		// after updating the world
		String signature = ty.getSignature();
		ResolvedType ret = typeMap.get(signature);
		if (ret != null) {
			ret.world = this; // Set the world for the RTX
			return ret;
		} else if (signature.equals("?") || signature.equals("*")) {
			// might be a problem here, not sure '?' should make it to here as a
			// signature, the
			// proper signature for wildcard '?' is '*'
			// fault in generic wildcard, can't be done earlier because of init
			// issues
			// TODO ought to be shared single instance representing this
			ResolvedType something = getWildcard();
			typeMap.put("?", something);
			return something;
		}

		// no existing resolved type, create one
		if (ty.isArray()) {
			ResolvedType componentType = resolve(ty.getComponentType(), allowMissing);
			// String brackets =
			// signature.substring(0,signature.lastIndexOf("[")+1);
			ret = new ArrayReferenceType(signature, "[" + componentType.getErasureSignature(), this, componentType);
		} else {
			ret = resolveToReferenceType(ty, allowMissing);
			if (!allowMissing && ret.isMissing()) {
				ret = handleRequiredMissingTypeDuringResolution(ty);
			}
			if (completeBinaryTypes) {
				completeBinaryType(ret);
			}
		}

		// Pulling in the type may have already put the right entry in the map
		ResolvedType result = typeMap.get(signature);
		if (result == null && !ret.isMissing()) {
			ret = ensureRawTypeIfNecessary(ret);
			typeMap.put(signature, ret);
			return ret;
		}
		if (result == null) {
			return ret;
		} else {
			return result;
		}
	}

	// Only need one representation of '?' in a world - can be shared
	private BoundedReferenceType wildcard;

	private BoundedReferenceType getWildcard() {
		if (wildcard == null) {
			wildcard = new BoundedReferenceType(this);
		}
		return wildcard;
	}

	/**
	 * Called when a type is resolved - enables its type hierarchy to be finished off before we proceed
	 */
	protected void completeBinaryType(ResolvedType ret) {
	}

	/**
	 * Return true if the classloader relating to this world is definetly the one that will define the specified class. Return false
	 * otherwise or we don't know for certain.
	 */
	public boolean isLocallyDefined(String classname) {
		return false;
	}

	/**
	 * We tried to resolve a type and couldn't find it...
	 */
	private ResolvedType handleRequiredMissingTypeDuringResolution(UnresolvedType ty) {
		// defer the message until someone asks a question of the type that we
		// can't answer
		// just from the signature.
		// MessageUtil.error(messageHandler,
		// WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE,ty.getName()));
		if (dumpState_cantFindTypeExceptions == null) {
			dumpState_cantFindTypeExceptions = new ArrayList<RuntimeException>();
		}
		if (dumpState_cantFindTypeExceptions.size() < 100) { // limit growth
			dumpState_cantFindTypeExceptions.add(new RuntimeException("Can't find type " + ty.getName()));
		}
		return new MissingResolvedTypeWithKnownSignature(ty.getSignature(), this);
	}

	/**
	 * Some TypeFactory operations create resolved types directly, but these won't be in the typeMap - this resolution process puts
	 * them there. Resolved types are also told their world which is needed for the special autoboxing resolved types.
	 */
	public ResolvedType resolve(ResolvedType ty) {
		if (ty.isTypeVariableReference()) {
			return ty; // until type variables have proper sigs...
		}
		ResolvedType resolved = typeMap.get(ty.getSignature());
		if (resolved == null) {
			resolved = ensureRawTypeIfNecessary(ty);
			typeMap.put(ty.getSignature(), resolved);
			resolved = ty;
		}
		resolved.world = this;
		return resolved;
	}

	/**
	 * When the world is operating in 1.5 mode, the TypeMap should only contain RAW types and never directly generic types. The RAW
	 * type will contain a reference to the generic type.
	 * 
	 * @param type a possibly generic type for which the raw needs creating as it is not currently in the world
	 * @return a type suitable for putting into the world
	 */
	private ResolvedType ensureRawTypeIfNecessary(ResolvedType type) {
		if (!isInJava5Mode() || type.isRawType()) {
			return type;
		}
		// Key requirement here is if it is generic, create a RAW entry to be put in the map that points to it
		if (type instanceof ReferenceType && ((ReferenceType) type).getDelegate() != null && type.isGenericType()) {
			ReferenceType rawType = new ReferenceType(type.getSignature(), this);
			rawType.typeKind = UnresolvedType.TypeKind.RAW;
			ReferenceTypeDelegate delegate = ((ReferenceType) type).getDelegate();
			rawType.setDelegate(delegate);
			rawType.setGenericType((ReferenceType) type);
			return rawType;
		}
		// probably parameterized...
		return type;
	}

	/**
	 * Convenience method for finding a type by name and resolving it in one step.
	 */
	public ResolvedType resolve(String name) {
		// trace.enter("resolve", this, new Object[] {name});
		ResolvedType ret = resolve(UnresolvedType.forName(name));
		// trace.exit("resolve", ret);
		return ret;
	}

	public ReferenceType resolveToReferenceType(String name) {
		return (ReferenceType) resolve(name);
	}

	public ResolvedType resolve(String name, boolean allowMissing) {
		return resolve(UnresolvedType.forName(name), allowMissing);
	}

	/**
	 * Resolve to a ReferenceType - simple, raw, parameterized, or generic. Raw, parameterized, and generic versions of a type share
	 * a delegate.
	 */
	private final ResolvedType resolveToReferenceType(UnresolvedType ty, boolean allowMissing) {
		if (ty.isParameterizedType()) {
			// ======= parameterized types ================
			ResolvedType rt = resolveGenericTypeFor(ty, allowMissing);
			if (rt.isMissing()) {
				return rt;
			}
			ReferenceType genericType = (ReferenceType) rt;
			ReferenceType parameterizedType = TypeFactory.createParameterizedType(genericType, ty.typeParameters, this);
			return parameterizedType;

		} else if (ty.isGenericType()) {
			// ======= generic types ======================
			ResolvedType rt = resolveGenericTypeFor(ty, false);
			ReferenceType genericType = (ReferenceType) rt;
			return genericType;

		} else if (ty.isGenericWildcard()) {
			// ======= generic wildcard types =============
			return resolveGenericWildcardFor((WildcardedUnresolvedType) ty);
		} else {
			// ======= simple and raw types ===============
			String erasedSignature = ty.getErasureSignature();
			ReferenceType simpleOrRawType = new ReferenceType(erasedSignature, this);
			if (ty.needsModifiableDelegate()) {
				simpleOrRawType.setNeedsModifiableDelegate(true);
			}
			ReferenceTypeDelegate delegate = resolveDelegate(simpleOrRawType);
			// 117854
			// if (delegate == null) return ResolvedType.MISSING;
			if (delegate == null) {
				return new MissingResolvedTypeWithKnownSignature(ty.getSignature(), erasedSignature, this);// ResolvedType
				// .
				// MISSING
				// ;
			}

			if (delegate.isGeneric() && behaveInJava5Way) {
				// ======== raw type ===========
				simpleOrRawType.typeKind = TypeKind.RAW;
				ReferenceType genericType = makeGenericTypeFrom(delegate, simpleOrRawType);
				// name =
				// ReferenceType.fromTypeX(UnresolvedType.forRawTypeNames(
				// ty.getName()),this);
				simpleOrRawType.setDelegate(delegate);
				genericType.setDelegate(delegate);
				simpleOrRawType.setGenericType(genericType);
				return simpleOrRawType;

			} else {
				// ======== simple type =========
				simpleOrRawType.setDelegate(delegate);
				return simpleOrRawType;
			}
		}
	}

	/**
	 * Attempt to resolve a type that should be a generic type.
	 */
	public ResolvedType resolveGenericTypeFor(UnresolvedType anUnresolvedType, boolean allowMissing) {
		// Look up the raw type by signature
		String rawSignature = anUnresolvedType.getRawType().getSignature();
		ResolvedType rawType = typeMap.get(rawSignature);
		if (rawType == null) {
			rawType = resolve(UnresolvedType.forSignature(rawSignature), allowMissing);
			typeMap.put(rawSignature, rawType);
		}
		if (rawType.isMissing()) {
			return rawType;
		}

		// Does the raw type know its generic form? (It will if we created the
		// raw type from a source type, it won't if its been created just
		// through
		// being referenced, e.g. java.util.List
		ResolvedType genericType = rawType.getGenericType();

		// There is a special case to consider here (testGenericsBang_pr95993
		// highlights it)
		// You may have an unresolvedType for a parameterized type but it
		// is backed by a simple type rather than a generic type. This occurs
		// for
		// inner types of generic types that inherit their enclosing types
		// type variables.
		if (rawType.isSimpleType() && (anUnresolvedType.typeParameters == null || anUnresolvedType.typeParameters.length == 0)) {
			rawType.world = this;
			return rawType;
		}

		if (genericType != null) {
			genericType.world = this;
			return genericType;
		} else {
			// Fault in the generic that underpins the raw type ;)
			ReferenceTypeDelegate delegate = resolveDelegate((ReferenceType) rawType);
			ReferenceType genericRefType = makeGenericTypeFrom(delegate, ((ReferenceType) rawType));
			((ReferenceType) rawType).setGenericType(genericRefType);
			genericRefType.setDelegate(delegate);
			((ReferenceType) rawType).setDelegate(delegate);
			return genericRefType;
		}
	}

	private ReferenceType makeGenericTypeFrom(ReferenceTypeDelegate delegate, ReferenceType rawType) {
		String genericSig = delegate.getDeclaredGenericSignature();
		if (genericSig != null) {
			return new ReferenceType(UnresolvedType.forGenericTypeSignature(rawType.getSignature(),
					delegate.getDeclaredGenericSignature()), this);
		} else {
			return new ReferenceType(UnresolvedType.forGenericTypeVariables(rawType.getSignature(), delegate.getTypeVariables()),
					this);
		}
	}

	/**
	 * Go from an unresolved generic wildcard (represented by UnresolvedType) to a resolved version (BoundedReferenceType).
	 */
	private ReferenceType resolveGenericWildcardFor(WildcardedUnresolvedType aType) {
		BoundedReferenceType ret = null;
		// FIXME asc doesnt take account of additional interface bounds (e.g. ?
		// super R & Serializable - can you do that?)
		if (aType.isExtends()) {
			ReferenceType upperBound = (ReferenceType) resolve(aType.getUpperBound());
			ret = new BoundedReferenceType(upperBound, true, this);
		} else if (aType.isSuper()) {
			ReferenceType lowerBound = (ReferenceType) resolve(aType.getLowerBound());
			ret = new BoundedReferenceType(lowerBound, false, this);
		} else {
			// must be ? on its own!
			ret = getWildcard();
		}
		return ret;
	}

	/**
	 * Find the ReferenceTypeDelegate behind this reference type so that it can fulfill its contract.
	 */
	protected abstract ReferenceTypeDelegate resolveDelegate(ReferenceType ty);

	/**
	 * Special resolution for "core" types like OBJECT. These are resolved just like any other type, but if they are not found it is
	 * more serious and we issue an error message immediately.
	 */
	// OPTIMIZE streamline path for core types? They are just simple types,
	// could look straight in the typemap?
	public ResolvedType getCoreType(UnresolvedType tx) {
		ResolvedType coreTy = resolve(tx, true);
		if (coreTy.isMissing()) {
			MessageUtil.error(messageHandler, WeaverMessages.format(WeaverMessages.CANT_FIND_CORE_TYPE, tx.getName()));
		}
		return coreTy;
	}

	/**
	 * Lookup a type by signature, if not found then build one and put it in the map.
	 */
	public ReferenceType lookupOrCreateName(UnresolvedType ty) {
		String signature = ty.getSignature();
		ReferenceType ret = lookupBySignature(signature);
		if (ret == null) {
			ret = ReferenceType.fromTypeX(ty, this);
			typeMap.put(signature, ret);
		}
		return ret;
	}

	/**
	 * Lookup a reference type in the world by its signature. Returns null if not found.
	 */
	public ReferenceType lookupBySignature(String signature) {
		return (ReferenceType) typeMap.get(signature);
	}

	// ==========================================================================
	// ===
	// T Y P E R E S O L U T I O N -- E N D
	// ==========================================================================
	// ===

	/**
	 * Member resolution is achieved by resolving the declaring type and then looking up the member in the resolved declaring type.
	 */
	public ResolvedMember resolve(Member member) {
		ResolvedType declaring = member.getDeclaringType().resolve(this);
		if (declaring.isRawType()) {
			declaring = declaring.getGenericType();
		}
		ResolvedMember ret;
		if (member.getKind() == Member.FIELD) {
			ret = declaring.lookupField(member);
		} else {
			ret = declaring.lookupMethod(member);
		}

		if (ret != null) {
			return ret;
		}

		return declaring.lookupSyntheticMember(member);
	}

	private boolean allLintIgnored = false;

	public void setAllLintIgnored() {
		allLintIgnored = true;
	}

	public boolean areAllLintIgnored() {
		return allLintIgnored;
	}

	public abstract IWeavingSupport getWeavingSupport();

	/**
	 * Create an advice shadow munger from the given advice attribute
	 */
	// public abstract Advice createAdviceMunger(AjAttribute.AdviceAttribute
	// attribute, Pointcut pointcut, Member signature);
	/**
	 * Create an advice shadow munger for the given advice kind
	 */
	public final Advice createAdviceMunger(AdviceKind kind, Pointcut p, Member signature, int extraParameterFlags,
			IHasSourceLocation loc, ResolvedType declaringAspect) {
		AjAttribute.AdviceAttribute attribute = new AjAttribute.AdviceAttribute(kind, p, extraParameterFlags, loc.getStart(),
				loc.getEnd(), loc.getSourceContext());
		return getWeavingSupport().createAdviceMunger(attribute, p, signature, declaringAspect);
	}

	/**
	 * Same signature as org.aspectj.util.PartialOrder.PartialComparable.compareTo
	 */
	public int compareByPrecedence(ResolvedType aspect1, ResolvedType aspect2) {
		return precedenceCalculator.compareByPrecedence(aspect1, aspect2);
	}

	public Integer getPrecedenceIfAny(ResolvedType aspect1, ResolvedType aspect2) {
		return precedenceCalculator.getPrecedenceIfAny(aspect1, aspect2);
	}

	/**
	 * compares by precedence with the additional rule that a super-aspect is sorted before its sub-aspects
	 */
	public int compareByPrecedenceAndHierarchy(ResolvedType aspect1, ResolvedType aspect2) {
		return precedenceCalculator.compareByPrecedenceAndHierarchy(aspect1, aspect2);
	}

	// simple property getter and setters
	// ===========================================================

	/**
	 * Nobody should hold onto a copy of this message handler, or setMessageHandler won't work right.
	 */
	public IMessageHandler getMessageHandler() {
		return messageHandler;
	}

	public void setMessageHandler(IMessageHandler messageHandler) {
		if (this.isInPinpointMode()) {
			this.messageHandler = new PinpointingMessageHandler(messageHandler);
		} else {
			this.messageHandler = messageHandler;
		}
	}

	/**
	 * convenenience method for creating and issuing messages via the message handler - if you supply two locations you will get two
	 * messages.
	 */
	public void showMessage(Kind kind, String message, ISourceLocation loc1, ISourceLocation loc2) {
		if (loc1 != null) {
			messageHandler.handleMessage(new Message(message, kind, null, loc1));
			if (loc2 != null) {
				messageHandler.handleMessage(new Message(message, kind, null, loc2));
			}
		} else {
			messageHandler.handleMessage(new Message(message, kind, null, loc2));
		}
	}

	public void setCrossReferenceHandler(ICrossReferenceHandler xrefHandler) {
		this.xrefHandler = xrefHandler;
	}

	/**
	 * Get the cross-reference handler for the world, may be null.
	 */
	public ICrossReferenceHandler getCrossReferenceHandler() {
		return xrefHandler;
	}

	public void setTypeVariableLookupScope(TypeVariableDeclaringElement scope) {
		typeVariableLookupScope = scope;
	}

	public TypeVariableDeclaringElement getTypeVariableLookupScope() {
		return typeVariableLookupScope;
	}

	public List<DeclareParents> getDeclareParents() {
		return crosscuttingMembersSet.getDeclareParents();
	}

	public List<DeclareAnnotation> getDeclareAnnotationOnTypes() {
		return crosscuttingMembersSet.getDeclareAnnotationOnTypes();
	}

	public List<DeclareAnnotation> getDeclareAnnotationOnFields() {
		return crosscuttingMembersSet.getDeclareAnnotationOnFields();
	}

	public List<DeclareAnnotation> getDeclareAnnotationOnMethods() {
		return crosscuttingMembersSet.getDeclareAnnotationOnMethods();
	}

	public List<DeclareTypeErrorOrWarning> getDeclareTypeEows() {
		return crosscuttingMembersSet.getDeclareTypeEows();
	}

	public List<DeclareSoft> getDeclareSoft() {
		return crosscuttingMembersSet.getDeclareSofts();
	}

	public CrosscuttingMembersSet getCrosscuttingMembersSet() {
		return crosscuttingMembersSet;
	}

	public IStructureModel getModel() {
		return model;
	}

	public void setModel(IStructureModel model) {
		this.model = model;
	}

	public Lint getLint() {
		return lint;
	}

	public void setLint(Lint lint) {
		this.lint = lint;
	}

	public boolean isXnoInline() {
		return XnoInline;
	}

	public void setXnoInline(boolean xnoInline) {
		XnoInline = xnoInline;
	}

	public boolean isXlazyTjp() {
		return XlazyTjp;
	}

	public void setXlazyTjp(boolean b) {
		XlazyTjp = b;
	}

	public boolean isHasMemberSupportEnabled() {
		return XhasMember;
	}

	public void setXHasMemberSupportEnabled(boolean b) {
		XhasMember = b;
	}

	public boolean isInPinpointMode() {
		return Xpinpoint;
	}

	public void setPinpointMode(boolean b) {
		Xpinpoint = b;
	}

	public boolean isMinimalModel() {
		ensureAdvancedConfigurationProcessed();
		return minimalModel;
	}

	public boolean isTargettingRuntime1_6_10() {
		ensureAdvancedConfigurationProcessed();
		return targettingRuntime1_6_10;
	}

	public void setBehaveInJava5Way(boolean b) {
		behaveInJava5Way = b;
	}

	/**
	 * Set the timing option (whether to collect timing info), this will also need INFO messages turned on for the message handler
	 * being used. The reportPeriodically flag should be set to false under AJDT so numbers just come out at the end.
	 */
	public void setTiming(boolean timersOn, boolean reportPeriodically) {
		timing = timersOn;
		timingPeriodically = reportPeriodically;
	}

	/**
	 * Set the error and warning threashold which can be taken from CompilerOptions (see bug 129282)
	 * 
	 * @param errorThreshold
	 * @param warningThreshold
	 */
	public void setErrorAndWarningThreshold(long errorThreshold, long warningThreshold) {
		this.errorThreshold = errorThreshold;
		this.warningThreshold = warningThreshold;
	}

	/**
	 * @return true if ignoring the UnusedDeclaredThrownException and false if this compiler option is set to error or warning
	 */
	public boolean isIgnoringUnusedDeclaredThrownException() {
		// the 0x800000 is CompilerOptions.UnusedDeclaredThrownException
		// which is ASTNode.bit24
		if ((errorThreshold & 0x800000) != 0 || (warningThreshold & 0x800000) != 0) {
			return false;
		}
		return true;
	}

	public void performExtraConfiguration(String config) {
		if (config == null) {
			return;
		}
		// Bunch of name value pairs to split
		extraConfiguration = new Properties();
		int pos = -1;
		while ((pos = config.indexOf(",")) != -1) {
			String nvpair = config.substring(0, pos);
			int pos2 = nvpair.indexOf("=");
			if (pos2 != -1) {
				String n = nvpair.substring(0, pos2);
				String v = nvpair.substring(pos2 + 1);
				extraConfiguration.setProperty(n, v);
			}
			config = config.substring(pos + 1);
		}
		if (config.length() > 0) {
			int pos2 = config.indexOf("=");
			if (pos2 != -1) {
				String n = config.substring(0, pos2);
				String v = config.substring(pos2 + 1);
				extraConfiguration.setProperty(n, v);
			}
		}
		ensureAdvancedConfigurationProcessed();
	}

	public boolean areInfoMessagesEnabled() {
		if (infoMessagesEnabled == 0) {
			infoMessagesEnabled = (messageHandler.isIgnoring(IMessage.INFO) ? 1 : 2);
		}
		return infoMessagesEnabled == 2;
	}

	/**
	 * may return null
	 */
	public Properties getExtraConfiguration() {
		return extraConfiguration;
	}

	public final static String xsetWEAVE_JAVA_PACKAGES = "weaveJavaPackages"; // default
	// false
	// -
	// controls
	// LTW
	public final static String xsetWEAVE_JAVAX_PACKAGES = "weaveJavaxPackages"; // default
	// false
	// -
	// controls
	// LTW
	public final static String xsetCAPTURE_ALL_CONTEXT = "captureAllContext"; // default
	// false
	public final static String xsetRUN_MINIMAL_MEMORY = "runMinimalMemory"; // default
	// true
	public final static String xsetDEBUG_STRUCTURAL_CHANGES_CODE = "debugStructuralChangesCode"; // default
	// false
	public final static String xsetDEBUG_BRIDGING = "debugBridging"; // default
	// false
	public final static String xsetBCEL_REPOSITORY_CACHING = "bcelRepositoryCaching";
	public final static String xsetPIPELINE_COMPILATION = "pipelineCompilation";
	public final static String xsetGENERATE_STACKMAPS = "generateStackMaps";
	public final static String xsetPIPELINE_COMPILATION_DEFAULT = "true";
	public final static String xsetCOMPLETE_BINARY_TYPES = "completeBinaryTypes";
	public final static String xsetCOMPLETE_BINARY_TYPES_DEFAULT = "false";
	public final static String xsetTYPE_DEMOTION = "typeDemotion";
	public final static String xsetTYPE_DEMOTION_DEBUG = "typeDemotionDebug";
	public final static String xsetTYPE_REFS = "useWeakTypeRefs";
	public final static String xsetBCEL_REPOSITORY_CACHING_DEFAULT = "true";
	public final static String xsetFAST_PACK_METHODS = "fastPackMethods"; // default true
	public final static String xsetOVERWEAVING = "overWeaving";
	public final static String xsetOPTIMIZED_MATCHING = "optimizedMatching";
	public final static String xsetTIMERS_PER_JOINPOINT = "timersPerJoinpoint";
	public final static String xsetTIMERS_PER_FASTMATCH_CALL = "timersPerFastMatchCall";
	public final static String xsetITD_VERSION = "itdVersion";
	public final static String xsetITD_VERSION_ORIGINAL = "1";
	public final static String xsetITD_VERSION_2NDGEN = "2";
	public final static String xsetITD_VERSION_DEFAULT = xsetITD_VERSION_2NDGEN;
	public final static String xsetMINIMAL_MODEL = "minimalModel";
	public final static String xsetTARGETING_RUNTIME_1610 = "targetRuntime1_6_10";

	public boolean isInJava5Mode() {
		return behaveInJava5Way;
	}

	public boolean isTimingEnabled() {
		return timing;
	}

	public void setTargetAspectjRuntimeLevel(String s) {
		targetAspectjRuntimeLevel = s;
	}

	public void setOptionalJoinpoints(String jps) {
		if (jps == null) {
			return;
		}
		if (jps.indexOf("arrayconstruction") != -1) {
			optionalJoinpoint_ArrayConstruction = true;
		}
		if (jps.indexOf("synchronization") != -1) {
			optionalJoinpoint_Synchronization = true;
		}
	}

	public boolean isJoinpointArrayConstructionEnabled() {
		return optionalJoinpoint_ArrayConstruction;
	}

	public boolean isJoinpointSynchronizationEnabled() {
		return optionalJoinpoint_Synchronization;
	}

	public String getTargetAspectjRuntimeLevel() {
		return targetAspectjRuntimeLevel;
	}

	// OPTIMIZE are users falling foul of not supplying -1.5 and so targetting
	// the old runtime?
	public boolean isTargettingAspectJRuntime12() {
		boolean b = false; // pr116679
		if (!isInJava5Mode()) {
			b = true;
		} else {
			b = getTargetAspectjRuntimeLevel().equals(org.aspectj.weaver.Constants.RUNTIME_LEVEL_12);
		}
		// System.err.println("Asked if targetting runtime 1.2 , returning: "+b);
		return b;
	}

	/*
	 * Map of types in the world, can have 'references' to expendable ones which can be garbage collected to recover memory. An
	 * expendable type is a reference type that is not exposed to the weaver (ie just pulled in for type resolution purposes).
	 */
	public static class TypeMap {

		// Strategy for entries in the expendable map
		public final static int DONT_USE_REFS = 0; // Hang around forever
		public final static int USE_WEAK_REFS = 1; // Collected asap
		public final static int USE_SOFT_REFS = 2; // Collected when short on memory

		public List<String> addedSinceLastDemote;
		public List<String> writtenClasses;

		private static boolean debug = false;
		public static boolean useExpendableMap = true; // configurable for reliable testing
		private boolean demotionSystemActive;
		private boolean debugDemotion = false;

		public int policy = USE_WEAK_REFS;

		// Map of types that never get thrown away
		final Map<String, ResolvedType> tMap = new HashMap<String, ResolvedType>();

		// Map of types that may be ejected from the cache if we need space
		final Map<String, Reference<ResolvedType>> expendableMap = Collections
				.synchronizedMap(new WeakHashMap<String, Reference<ResolvedType>>());

		private final World w;

		// profiling tools...
		private boolean memoryProfiling = false;
		private int maxExpendableMapSize = -1;
		private int collectedTypes = 0;
		private final ReferenceQueue<ResolvedType> rq = new ReferenceQueue<ResolvedType>();

		// private static Trace trace = TraceFactory.getTraceFactory().getTrace(World.TypeMap.class);

		TypeMap(World w) {
			// Demotion activated when switched on and loadtime weaving or in AJDT
			demotionSystemActive = w.isDemotionActive() && (w.isLoadtimeWeaving() || w.couldIncrementalCompileFollow());
			addedSinceLastDemote = new ArrayList<String>();
			writtenClasses = new ArrayList<String>();
			this.w = w;
			memoryProfiling = false;// !w.getMessageHandler().isIgnoring(Message.
			// INFO);
		}

		// For testing
		public Map<String, Reference<ResolvedType>> getExpendableMap() {
			return expendableMap;
		}

		// For testing
		public Map<String, ResolvedType> getMainMap() {
			return tMap;
		}

		public int demote() {
			return demote(false);
		}

		/**
		 * Go through any types added during the previous file weave. If any are suitable for demotion, then put them in the
		 * expendable map where GC can claim them at some point later. Demotion means: the type is not an aspect, the type is not
		 * java.lang.Object, the type is not primitive and the type is not affected by type mungers in any way. Further refinements
		 * of these conditions may allow for more demotions.
		 * 
		 * @return number of types demoted
		 */
		public int demote(boolean atEndOfCompile) {
			if (!demotionSystemActive) {
				return 0;
			}
			if (debugDemotion) {
				System.out.println("Demotion running " + addedSinceLastDemote);
			}
			boolean isLtw = w.isLoadtimeWeaving();
			int demotionCounter = 0;
			if (isLtw) {
				// Loadtime weaving demotion strategy
				for (String key : addedSinceLastDemote) {
					ResolvedType type = tMap.get(key);
					if (type != null && !type.isAspect() && !type.equals(UnresolvedType.OBJECT) && !type.isPrimitiveType()) {
						List<ConcreteTypeMunger> typeMungers = type.getInterTypeMungers();
						if (typeMungers == null || typeMungers.size() == 0) {
							tMap.remove(key);
							insertInExpendableMap(key, type);
							demotionCounter++;
						}
					}
				}
				addedSinceLastDemote.clear();
			} else {
				// Compile time demotion strategy
				List<String> forRemoval = new ArrayList<String>();
				for (String key : addedSinceLastDemote) {
					ResolvedType type = tMap.get(key);
					if (type == null) {
						// TODO not 100% sure why it is not there, where did it go?
						forRemoval.add(key);
						continue;
					}
					if (!writtenClasses.contains(type.getName())) { // COSTLY
						continue;
					}
					if (type != null && !type.isAspect() && !type.equals(UnresolvedType.OBJECT) && !type.isPrimitiveType()) {
						List<ConcreteTypeMunger> typeMungers = type.getInterTypeMungers();
						if (typeMungers == null || typeMungers.size() == 0) {
							/*
							 * if (type.isNested()) { try { ReferenceType rt = (ReferenceType) w.resolve(type.getOutermostType());
							 * if (!rt.isMissing()) { ReferenceTypeDelegate delegate = ((ReferenceType) type).getDelegate(); boolean
							 * isWeavable = delegate == null ? false : delegate.isExposedToWeaver(); boolean hasBeenWoven = delegate
							 * == null ? false : delegate.hasBeenWoven(); if (isWeavable && !hasBeenWoven) { // skip demotion of
							 * this inner type for now continue; } } } catch (ClassCastException cce) { cce.printStackTrace();
							 * System.out.println("outer of " + key + " is not a reftype? " + type.getOutermostType()); // throw new
							 * IllegalStateException(cce); } }
							 */
							ReferenceTypeDelegate delegate = ((ReferenceType) type).getDelegate();
							boolean isWeavable = delegate == null ? false : delegate.isExposedToWeaver();
							boolean hasBeenWoven = delegate == null ? false : delegate.hasBeenWoven();
							if (!isWeavable || hasBeenWoven) {
								if (debugDemotion) {
									System.out.println("Demoting " + key);
								}
								forRemoval.add(key);
								tMap.remove(key);
								insertInExpendableMap(key, type);
								demotionCounter++;
							}
						} else {
							// no need to try this again, it will never be demoted
							writtenClasses.remove(type.getName());
							forRemoval.add(key);
						}
					} else {
						writtenClasses.remove(type.getName());
						// no need to try this again, it will never be demoted
						forRemoval.add(key);
					}
				}
				addedSinceLastDemote.removeAll(forRemoval);
			}
			if (debugDemotion) {
				System.out.println("Demoted " + demotionCounter + " types.  Types remaining in fixed set #" + tMap.keySet().size()
						+ ".  addedSinceLastDemote size is " + addedSinceLastDemote.size());
				System.out.println("writtenClasses.size() = " + writtenClasses.size() + ": " + writtenClasses);
			}
			if (atEndOfCompile) {
				if (debugDemotion) {
					System.out.println("Clearing writtenClasses");
				}
				writtenClasses.clear();
			}
			return demotionCounter;
		}

		private void insertInExpendableMap(String key, ResolvedType type) {
			if (useExpendableMap) {
				if (!expendableMap.containsKey(key)) {
					if (policy == USE_SOFT_REFS) {
						expendableMap.put(key, new SoftReference<ResolvedType>(type));
					} else {
						expendableMap.put(key, new WeakReference<ResolvedType>(type));
					}
				}
			}
		}

		/**
		 * 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
		 * *member* type variables. The reason is that when all you have is the signature which gives you a type variable name, you
		 * cannot guarantee you are using the type variable in the same way as someone previously working with a similarly named
		 * type variable. So, these do not go into the map: - TypeVariableReferenceType. - ParameterizedType where a member type
		 * variable is involved. - BoundedReferenceType when one of the bounds is a type variable.
		 * 
		 * definition: "member type variables" - a tvar declared on a generic method/ctor as opposed to those you see declared on a
		 * generic type.
		 */
		public ResolvedType put(String key, ResolvedType type) {
			if (!type.isCacheable()) {
				return type;
			}
			if (type.isParameterizedType() && type.isParameterizedWithTypeVariable()) {
				if (debug) {
					System.err
							.println("Not putting a parameterized type that utilises member declared type variables into the typemap: key="
									+ key + " type=" + type);
				}
				return type;
			}
			if (type.isTypeVariableReference()) {
				if (debug) {
					System.err.println("Not putting a type variable reference type into the typemap: key=" + key + " type=" + type);
				}
				return type;
			}
			// this test should be improved - only avoid putting them in if one
			// of the
			// bounds is a member type variable
			if (type instanceof BoundedReferenceType) {
				if (debug) {
					System.err.println("Not putting a bounded reference type into the typemap: key=" + key + " type=" + type);
				}
				return type;
			}
			if (type instanceof MissingResolvedTypeWithKnownSignature) {
				if (debug) {
					System.err.println("Not putting a missing type into the typemap: key=" + key + " type=" + type);
				}
				return type;
			}

			if ((type instanceof ReferenceType) && (((ReferenceType) type).getDelegate() == null) && w.isExpendable(type)) {
				if (debug) {
					System.err.println("Not putting expendable ref type with null delegate into typemap: key=" + key + " type="
							+ type);
				}
				return type;
			}

			// TODO should this be in as a permanent assertion?
			/*
			 * if ((type instanceof ReferenceType) && type.getWorld().isInJava5Mode() && (((ReferenceType) type).getDelegate() !=
			 * null) && type.isGenericType()) { throw new BCException("Attempt to add generic type to typemap " + type.toString() +
			 * " (should be raw)"); }
			 */

			if (w.isExpendable(type)) {
				if (useExpendableMap) {
					// Dont use reference queue for tracking if not profiling...
					if (policy == USE_WEAK_REFS) {
						if (memoryProfiling) {
							expendableMap.put(key, new WeakReference<ResolvedType>(type, rq));
						} else {
							expendableMap.put(key, new WeakReference<ResolvedType>(type));
						}
					} else if (policy == USE_SOFT_REFS) {
						if (memoryProfiling) {
							expendableMap.put(key, new SoftReference<ResolvedType>(type, rq));
						} else {
							expendableMap.put(key, new SoftReference<ResolvedType>(type));
						}
						// } else {
						// expendableMap.put(key, type);
					}
				}
				if (memoryProfiling && expendableMap.size() > maxExpendableMapSize) {
					maxExpendableMapSize = expendableMap.size();
				}
				return type;
			} else {

				if (demotionSystemActive) {
					// System.out.println("Added since last demote " + key);
					addedSinceLastDemote.add(key);
				}

				return tMap.put(key, type);
			}
		}

		public void report() {
			if (!memoryProfiling) {
				return;
			}
			checkq();
			w.getMessageHandler().handleMessage(
					MessageUtil.info("MEMORY: world expendable type map reached maximum size of #" + maxExpendableMapSize
							+ " entries"));
			w.getMessageHandler().handleMessage(
					MessageUtil.info("MEMORY: types collected through garbage collection #" + collectedTypes + " entries"));
		}

		public void checkq() {
			if (!memoryProfiling) {
				return;
			}
			while (rq.poll() != null) {
				collectedTypes++;
			}
		}

		/**
		 * Lookup a type by its signature, always look in the real map before the expendable map
		 */
		public ResolvedType get(String key) {
			checkq();
			ResolvedType ret = tMap.get(key);
			if (ret == null) {
				if (policy == USE_WEAK_REFS) {
					WeakReference<ResolvedType> ref = (WeakReference<ResolvedType>) expendableMap.get(key);
					if (ref != null) {
						ret = ref.get();
					}
				} else if (policy == USE_SOFT_REFS) {
					SoftReference<ResolvedType> ref = (SoftReference<ResolvedType>) expendableMap.get(key);
					if (ref != null) {
						ret = ref.get();
					}
					// } else {
					// return (ResolvedType) expendableMap.get(key);
				}
			}
			return ret;
		}

		/** Remove a type from the map */
		public ResolvedType remove(String key) {
			ResolvedType ret = tMap.remove(key);
			if (ret == null) {
				if (policy == USE_WEAK_REFS) {
					WeakReference<ResolvedType> wref = (WeakReference<ResolvedType>) expendableMap.remove(key);
					if (wref != null) {
						ret = wref.get();
					}
				} else if (policy == USE_SOFT_REFS) {
					SoftReference<ResolvedType> wref = (SoftReference<ResolvedType>) expendableMap.remove(key);
					if (wref != null) {
						ret = wref.get();
					}
					// } else {
					// ret = (ResolvedType) expendableMap.remove(key);
				}
			}
			return ret;
		}

		public void classWriteEvent(String classname) {
			// that is a name com.Foo and not a signature Lcom/Foo; boooooooooo!
			if (demotionSystemActive) {
				writtenClasses.add(classname);
			}
			if (debugDemotion) {
				System.out.println("Class write event for " + classname);
			}
		}

		// public ResolvedType[] getAllTypes() {
		// List/* ResolvedType */results = new ArrayList();
		//
		// collectTypes(expendableMap, results);
		// collectTypes(tMap, results);
		// return (ResolvedType[]) results.toArray(new
		// ResolvedType[results.size()]);
		// }
		//
		// private void collectTypes(Map map, List/* ResolvedType */results) {
		// for (Iterator iterator = map.keySet().iterator();
		// iterator.hasNext();) {
		// String key = (String) iterator.next();
		// ResolvedType type = get(key);
		// if (type != null)
		// results.add(type);
		// else
		// System.err.println("null!:" + key);
		// }
		// }

	}

	/**
	 * This class is used to compute and store precedence relationships between aspects.
	 */
	private static class AspectPrecedenceCalculator {

		private final World world;
		private final Map<PrecedenceCacheKey, Integer> cachedResults;

		public AspectPrecedenceCalculator(World forSomeWorld) {
			world = forSomeWorld;
			cachedResults = new HashMap<PrecedenceCacheKey, Integer>();
		}

		/**
		 * Ask every declare precedence in the world to order the two aspects. If more than one declare precedence gives an
		 * ordering, and the orderings conflict, then that's an error.
		 */
		public int compareByPrecedence(ResolvedType firstAspect, ResolvedType secondAspect) {
			PrecedenceCacheKey key = new PrecedenceCacheKey(firstAspect, secondAspect);
			if (cachedResults.containsKey(key)) {
				return (cachedResults.get(key)).intValue();
			} else {
				int order = 0;
				DeclarePrecedence orderer = null; // Records the declare
				// precedence statement that
				// gives the first ordering
				for (Iterator<Declare> i = world.getCrosscuttingMembersSet().getDeclareDominates().iterator(); i.hasNext();) {
					DeclarePrecedence d = (DeclarePrecedence) i.next();
					int thisOrder = d.compare(firstAspect, secondAspect);
					if (thisOrder != 0) {
						if (orderer == null) {
							orderer = d;
						}
						if (order != 0 && order != thisOrder) {
							ISourceLocation[] isls = new ISourceLocation[2];
							isls[0] = orderer.getSourceLocation();
							isls[1] = d.getSourceLocation();
							Message m = new Message("conflicting declare precedence orderings for aspects: "
									+ firstAspect.getName() + " and " + secondAspect.getName(), null, true, isls);
							world.getMessageHandler().handleMessage(m);
						} else {
							order = thisOrder;
						}
					}
				}
				cachedResults.put(key, new Integer(order));
				return order;
			}
		}

		public Integer getPrecedenceIfAny(ResolvedType aspect1, ResolvedType aspect2) {
			return cachedResults.get(new PrecedenceCacheKey(aspect1, aspect2));
		}

		public int compareByPrecedenceAndHierarchy(ResolvedType firstAspect, ResolvedType secondAspect) {
			if (firstAspect.equals(secondAspect)) {
				return 0;
			}

			int ret = compareByPrecedence(firstAspect, secondAspect);
			if (ret != 0) {
				return ret;
			}

			if (firstAspect.isAssignableFrom(secondAspect)) {
				return -1;
			} else if (secondAspect.isAssignableFrom(firstAspect)) {
				return +1;
			}

			return 0;
		}

		private static class PrecedenceCacheKey {
			public ResolvedType aspect1;
			public ResolvedType aspect2;

			public PrecedenceCacheKey(ResolvedType a1, ResolvedType a2) {
				aspect1 = a1;
				aspect2 = a2;
			}

			@Override
			public boolean equals(Object obj) {
				if (!(obj instanceof PrecedenceCacheKey)) {
					return false;
				}
				PrecedenceCacheKey other = (PrecedenceCacheKey) obj;
				return (aspect1 == other.aspect1 && aspect2 == other.aspect2);
			}

			@Override
			public int hashCode() {
				return aspect1.hashCode() + aspect2.hashCode();
			}
		}
	}

	public void validateType(UnresolvedType type) {
	}

	// --- with java5 we can get into a recursive mess if we aren't careful when
	// resolving types (*cough* java.lang.Enum) ---

	public boolean isDemotionActive() {
		return false;
	}

	// --- this first map is for java15 delegates which may try and recursively
	// access the same type variables.
	// --- I would rather stash this against a reference type - but we don't
	// guarantee referencetypes are unique for
	// so we can't :(
	private final Map<Class<?>, TypeVariable[]> workInProgress1 = new HashMap<Class<?>, TypeVariable[]>();

	public TypeVariable[] getTypeVariablesCurrentlyBeingProcessed(Class<?> baseClass) {
		return workInProgress1.get(baseClass);
	}

	public void recordTypeVariablesCurrentlyBeingProcessed(Class<?> baseClass, TypeVariable[] typeVariables) {
		workInProgress1.put(baseClass, typeVariables);
	}

	public void forgetTypeVariablesCurrentlyBeingProcessed(Class<?> baseClass) {
		workInProgress1.remove(baseClass);
	}

	public void setAddSerialVerUID(boolean b) {
		addSerialVerUID = b;
	}

	public boolean isAddSerialVerUID() {
		return addSerialVerUID;
	}

	/** be careful calling this - pr152257 */
	public void flush() {
		typeMap.expendableMap.clear();
	}

	public void ensureAdvancedConfigurationProcessed() {

		// Check *once* whether the user has switched asm support off
		if (!checkedAdvancedConfiguration) {
			Properties p = getExtraConfiguration();
			if (p != null) {

				String s = p.getProperty(xsetBCEL_REPOSITORY_CACHING, xsetBCEL_REPOSITORY_CACHING_DEFAULT);
				bcelRepositoryCaching = s.equalsIgnoreCase("true");
				if (!bcelRepositoryCaching) {
					getMessageHandler().handleMessage(
							MessageUtil
									.info("[bcelRepositoryCaching=false] AspectJ will not use a bcel cache for class information"));
				}

				// ITD Versions
				// 1 is the first version in use up to AspectJ 1.6.8
				// 2 is from 1.6.9 onwards
				s = p.getProperty(xsetITD_VERSION, xsetITD_VERSION_DEFAULT);
				if (s.equals(xsetITD_VERSION_ORIGINAL)) {
					itdVersion = 1;
				}

				s = p.getProperty(xsetMINIMAL_MODEL, "false");
				if (s.equalsIgnoreCase("true")) {
					minimalModel = true;
				}

				s = p.getProperty(xsetTARGETING_RUNTIME_1610, "false");
				if (s.equalsIgnoreCase("true")) {
					targettingRuntime1_6_10 = true;
				}

				s = p.getProperty(xsetFAST_PACK_METHODS, "true");
				fastMethodPacking = s.equalsIgnoreCase("true");

				s = p.getProperty(xsetPIPELINE_COMPILATION, xsetPIPELINE_COMPILATION_DEFAULT);
				shouldPipelineCompilation = s.equalsIgnoreCase("true");

				s = p.getProperty(xsetGENERATE_STACKMAPS, "false");
				shouldGenerateStackMaps = s.equalsIgnoreCase("true");

				s = p.getProperty(xsetCOMPLETE_BINARY_TYPES, xsetCOMPLETE_BINARY_TYPES_DEFAULT);
				completeBinaryTypes = s.equalsIgnoreCase("true");
				if (completeBinaryTypes) {
					getMessageHandler().handleMessage(
							MessageUtil.info("[completeBinaryTypes=true] Completion of binary types activated"));
				}

				s = p.getProperty(xsetTYPE_DEMOTION); // default is: ON (for ltw) OFF (for ctw)
				if (s != null) {
					boolean b = typeMap.demotionSystemActive;
					if (b && s.equalsIgnoreCase("false")) {
						System.out.println("typeDemotion=false: type demotion switched OFF");
						typeMap.demotionSystemActive = false;
					} else if (!b && s.equalsIgnoreCase("true")) {
						System.out.println("typeDemotion=true: type demotion switched ON");
						typeMap.demotionSystemActive = true;
					}
				}

				s = p.getProperty(xsetOVERWEAVING, "false");
				if (s.equalsIgnoreCase("true")) {
					overWeaving = true;
				}

				s = p.getProperty(xsetTYPE_DEMOTION_DEBUG, "false");
				if (s.equalsIgnoreCase("true")) {
					typeMap.debugDemotion = true;
				}
				s = p.getProperty(xsetTYPE_REFS, "true");
				if (s.equalsIgnoreCase("false")) {
					typeMap.policy = TypeMap.USE_SOFT_REFS;
				}

				runMinimalMemorySet = p.getProperty(xsetRUN_MINIMAL_MEMORY) != null;
				s = p.getProperty(xsetRUN_MINIMAL_MEMORY, "false");
				runMinimalMemory = s.equalsIgnoreCase("true");
				// if (runMinimalMemory)
				// getMessageHandler().handleMessage(MessageUtil.info(
				// "[runMinimalMemory=true] Optimizing bcel processing (and cost of performance) to use less memory"
				// ));

				s = p.getProperty(xsetDEBUG_STRUCTURAL_CHANGES_CODE, "false");
				forDEBUG_structuralChangesCode = s.equalsIgnoreCase("true");

				s = p.getProperty(xsetDEBUG_BRIDGING, "false");
				forDEBUG_bridgingCode = s.equalsIgnoreCase("true");

				s = p.getProperty(xsetOPTIMIZED_MATCHING, "true");
				optimizedMatching = s.equalsIgnoreCase("true");
				if (!optimizedMatching) {
					getMessageHandler().handleMessage(MessageUtil.info("[optimizedMatching=false] optimized matching turned off"));
				}

				s = p.getProperty(xsetTIMERS_PER_JOINPOINT, "25000");
				try {
					timersPerJoinpoint = Integer.parseInt(s);
				} catch (Exception e) {
					getMessageHandler().handleMessage(MessageUtil.error("unable to process timersPerJoinpoint value of " + s));
					timersPerJoinpoint = 25000;
				}

				s = p.getProperty(xsetTIMERS_PER_FASTMATCH_CALL, "250");
				try {
					timersPerType = Integer.parseInt(s);
				} catch (Exception e) {
					getMessageHandler().handleMessage(MessageUtil.error("unable to process timersPerType value of " + s));
					timersPerType = 250;
				}

			}
			try {
				String value = System.getProperty("aspectj.overweaving", "false");
				if (value.equalsIgnoreCase("true")) {
					System.out.println("ASPECTJ: aspectj.overweaving=true: overweaving switched ON");
					overWeaving = true;
				}
				value = System.getProperty("aspectj.typeDemotion", "false");
				if (value.equalsIgnoreCase("true")) {
					System.out.println("ASPECTJ: aspectj.typeDemotion=true: type demotion switched ON");
					typeMap.demotionSystemActive = true;
				}
				value = System.getProperty("aspectj.minimalModel", "false");
				if (value.equalsIgnoreCase("true")) {
					System.out.println("ASPECTJ: aspectj.minimalModel=true: minimal model switched ON");
					minimalModel = true;
				}
			} catch (Throwable t) {
				System.err.println("ASPECTJ: Unable to read system properties");
				t.printStackTrace();
			}
			checkedAdvancedConfiguration = true;
		}
	}

	public boolean isRunMinimalMemory() {
		ensureAdvancedConfigurationProcessed();
		return runMinimalMemory;
	}

	public boolean isRunMinimalMemorySet() {
		ensureAdvancedConfigurationProcessed();
		return runMinimalMemorySet;
	}

	public boolean shouldFastPackMethods() {
		ensureAdvancedConfigurationProcessed();
		return fastMethodPacking;
	}

	public boolean shouldPipelineCompilation() {
		ensureAdvancedConfigurationProcessed();
		return shouldPipelineCompilation;
	}

	public boolean shouldGenerateStackMaps() {
		ensureAdvancedConfigurationProcessed();
		return shouldGenerateStackMaps;
	}

	public void setIncrementalCompileCouldFollow(boolean b) {
		incrementalCompileCouldFollow = b;
	}

	public boolean couldIncrementalCompileFollow() {
		return incrementalCompileCouldFollow;
	}

	public void setSynchronizationPointcutsInUse() {
		if (trace.isTraceEnabled()) {
			trace.enter("setSynchronizationPointcutsInUse", this);
		}
		synchronizationPointcutsInUse = true;
		if (trace.isTraceEnabled()) {
			trace.exit("setSynchronizationPointcutsInUse");
		}
	}

	public boolean areSynchronizationPointcutsInUse() {
		return synchronizationPointcutsInUse;
	}

	/**
	 * Register a new pointcut designator handler with the world - this can be used by any pointcut parsers attached to the world.
	 * 
	 * @param designatorHandler handler for the new pointcut
	 */
	public void registerPointcutHandler(PointcutDesignatorHandler designatorHandler) {
		if (pointcutDesignators == null) {
			pointcutDesignators = new HashSet<PointcutDesignatorHandler>();
		}
		pointcutDesignators.add(designatorHandler);
	}

	public Set<PointcutDesignatorHandler> getRegisteredPointcutHandlers() {
		if (pointcutDesignators == null) {
			return Collections.emptySet();
		}
		return pointcutDesignators;
	}

	public void reportMatch(ShadowMunger munger, Shadow shadow) {

	}

	public boolean isOverWeaving() {
		return overWeaving;
	}

	public void reportCheckerMatch(Checker checker, Shadow shadow) {
	}

	/**
	 * @return true if this world has the activation and scope of application of the aspects controlled via aop.xml files
	 */
	public boolean isXmlConfigured() {
		return false;
	}

	public boolean isAspectIncluded(ResolvedType aspectType) {
		return true;
	}

	/**
	 * Determine if the named aspect requires a particular type around in order to be useful. The type is named in the aop.xml file
	 * against the aspect.
	 * 
	 * @return true if there is a type missing that this aspect really needed around
	 */
	public boolean hasUnsatisfiedDependency(ResolvedType aspectType) {
		return false;
	}

	public TypePattern getAspectScope(ResolvedType declaringType) {
		return null;
	}

	public Map<String, ResolvedType> getFixed() {
		return typeMap.tMap;
	}

	public Map<String, Reference<ResolvedType>> getExpendable() {
		return typeMap.expendableMap;
	}

	/**
	 * Ask the type map to demote any types it can - we don't want them anchored forever.
	 */
	public void demote() {
		typeMap.demote();
	}

	// protected boolean isExpendable(ResolvedType type) {
	// if (type.equals(UnresolvedType.OBJECT))
	// return false;
	// if (type == null)
	// return false;
	// boolean isExposed = type.isExposedToWeaver();
	// boolean nullDele = (type instanceof ReferenceType) ? ((ReferenceType) type).getDelegate() != null : true;
	// if (isExposed || !isExposed && nullDele)
	// return false;
	// return !type.isPrimitiveType();
	// }

	/**
	 * Reference types we don't intend to weave may be ejected from the cache if we need the space.
	 */
	protected boolean isExpendable(ResolvedType type) {
		return (!type.equals(UnresolvedType.OBJECT) && (!type.isExposedToWeaver()) && (!type.isPrimitiveType()));
	}

	// map from aspect > excluded types
	// memory issue here?
	private Map<ResolvedType, Set<ResolvedType>> exclusionMap = new HashMap<ResolvedType, Set<ResolvedType>>();

	public Map<ResolvedType, Set<ResolvedType>> getExclusionMap() {
		return exclusionMap;
	}

	private TimeCollector timeCollector = null;

	/**
	 * Record the time spent matching a pointcut - this will accumulate over the lifetime of this world/weaver and be reported every
	 * 25000 join points.
	 */
	public void record(Pointcut pointcut, long timetaken) {
		if (timeCollector == null) {
			ensureAdvancedConfigurationProcessed();
			timeCollector = new TimeCollector(this);
		}
		timeCollector.record(pointcut, timetaken);
	}

	/**
	 * Record the time spent fastmatching a pointcut - this will accumulate over the lifetime of this world/weaver and be reported
	 * every 250 types.
	 */
	public void recordFastMatch(Pointcut pointcut, long timetaken) {
		if (timeCollector == null) {
			ensureAdvancedConfigurationProcessed();
			timeCollector = new TimeCollector(this);
		}
		timeCollector.recordFastMatch(pointcut, timetaken);
	}

	public void reportTimers() {
		if (timeCollector != null && !timingPeriodically) {
			timeCollector.report();
			timeCollector = new TimeCollector(this);
		}
	}

	private static class TimeCollector {
		private World world;
		long joinpointCount;
		long typeCount;
		long perJoinpointCount;
		long perTypes;
		Map<String, Long> joinpointsPerPointcut = new HashMap<String, Long>();
		Map<String, Long> timePerPointcut = new HashMap<String, Long>();
		Map<String, Long> fastMatchTimesPerPointcut = new HashMap<String, Long>();
		Map<String, Long> fastMatchTypesPerPointcut = new HashMap<String, Long>();

		TimeCollector(World world) {
			this.perJoinpointCount = world.timersPerJoinpoint;
			this.perTypes = world.timersPerType;
			this.world = world;
			this.joinpointCount = 0;
			this.typeCount = 0;
			this.joinpointsPerPointcut = new HashMap<String, Long>();
			this.timePerPointcut = new HashMap<String, Long>();
		}

		public void report() {
			long totalTime = 0L;
			for (String p : joinpointsPerPointcut.keySet()) {
				totalTime += timePerPointcut.get(p);
			}
			world.getMessageHandler().handleMessage(
					MessageUtil.info("Pointcut matching cost (total=" + (totalTime / 1000000) + "ms for " + joinpointCount
							+ " joinpoint match calls):"));
			for (String p : joinpointsPerPointcut.keySet()) {
				StringBuffer sb = new StringBuffer();
				sb.append("Time:" + (timePerPointcut.get(p) / 1000000) + "ms (jps:#" + joinpointsPerPointcut.get(p)
						+ ") matching against " + p);
				world.getMessageHandler().handleMessage(MessageUtil.info(sb.toString()));
			}
			world.getMessageHandler().handleMessage(MessageUtil.info("---"));

			totalTime = 0L;
			for (String p : fastMatchTimesPerPointcut.keySet()) {
				totalTime += fastMatchTimesPerPointcut.get(p);
			}
			world.getMessageHandler().handleMessage(
					MessageUtil.info("Pointcut fast matching cost (total=" + (totalTime / 1000000) + "ms for " + typeCount
							+ " fast match calls):"));
			for (String p : fastMatchTimesPerPointcut.keySet()) {
				StringBuffer sb = new StringBuffer();
				sb.append("Time:" + (fastMatchTimesPerPointcut.get(p) / 1000000) + "ms (types:#" + fastMatchTypesPerPointcut.get(p)
						+ ") fast matching against " + p);
				world.getMessageHandler().handleMessage(MessageUtil.info(sb.toString()));
			}
			world.getMessageHandler().handleMessage(MessageUtil.info("---"));

		}

		void record(Pointcut pointcut, long timetakenInNs) {
			joinpointCount++;
			String pointcutText = pointcut.toString();
			Long jpcounter = joinpointsPerPointcut.get(pointcutText);
			if (jpcounter == null) {
				jpcounter = 1L;
			} else {
				jpcounter++;
			}
			joinpointsPerPointcut.put(pointcutText, jpcounter);

			Long time = timePerPointcut.get(pointcutText);
			if (time == null) {
				time = timetakenInNs;
			} else {
				time += timetakenInNs;
			}
			timePerPointcut.put(pointcutText, time);
			if (world.timingPeriodically) {
				if ((joinpointCount % perJoinpointCount) == 0) {
					long totalTime = 0L;
					for (String p : joinpointsPerPointcut.keySet()) {
						totalTime += timePerPointcut.get(p);
					}
					world.getMessageHandler().handleMessage(
							MessageUtil.info("Pointcut matching cost (total=" + (totalTime / 1000000) + "ms for " + joinpointCount
									+ " joinpoint match calls):"));
					for (String p : joinpointsPerPointcut.keySet()) {
						StringBuffer sb = new StringBuffer();
						sb.append("Time:" + (timePerPointcut.get(p) / 1000000) + "ms (jps:#" + joinpointsPerPointcut.get(p)
								+ ") matching against " + p);
						world.getMessageHandler().handleMessage(MessageUtil.info(sb.toString()));
					}
					world.getMessageHandler().handleMessage(MessageUtil.info("---"));
				}
			}
		}

		void recordFastMatch(Pointcut pointcut, long timetakenInNs) {
			typeCount++;
			String pointcutText = pointcut.toString();
			Long typecounter = fastMatchTypesPerPointcut.get(pointcutText);
			if (typecounter == null) {
				typecounter = 1L;
			} else {
				typecounter++;
			}
			fastMatchTypesPerPointcut.put(pointcutText, typecounter);

			Long time = fastMatchTimesPerPointcut.get(pointcutText);
			if (time == null) {
				time = timetakenInNs;
			} else {
				time += timetakenInNs;
			}
			fastMatchTimesPerPointcut.put(pointcutText, time);
			if (world.timingPeriodically) {
				if ((typeCount % perTypes) == 0) {
					long totalTime = 0L;
					for (String p : fastMatchTimesPerPointcut.keySet()) {
						totalTime += fastMatchTimesPerPointcut.get(p);
					}
					world.getMessageHandler().handleMessage(
							MessageUtil.info("Pointcut fast matching cost (total=" + (totalTime / 1000000) + "ms for " + typeCount
									+ " fast match calls):"));
					for (String p : fastMatchTimesPerPointcut.keySet()) {
						StringBuffer sb = new StringBuffer();
						sb.append("Time:" + (fastMatchTimesPerPointcut.get(p) / 1000000) + "ms (types:#"
								+ fastMatchTypesPerPointcut.get(p) + ") fast matching against " + p);
						world.getMessageHandler().handleMessage(MessageUtil.info(sb.toString()));
					}
					world.getMessageHandler().handleMessage(MessageUtil.info("---"));
				}
			}
		}
	}

	public TypeMap getTypeMap() {
		return typeMap;
	}

	public static void reset() {
		ResolvedType.resetPrimitives();
	}

	/**
	 * Returns the version of ITD that this world wants to create. The default is the new style (2) but in some cases where there
	 * might be a clash, the old style can be used. It is set through the option -Xset:itdVersion=1
	 * 
	 * @return the ITD version this world wants to create - 1=oldstyle 2=new, transparent style
	 */
	public int getItdVersion() {
		return itdVersion;
	}

	// if not loadtime weaving then we are compile time weaving or post-compile time weaving
	public abstract boolean isLoadtimeWeaving();

	public void classWriteEvent(char[][] compoundName) {
		// override if interested in write events
	}

}