-
Notifications
You must be signed in to change notification settings - Fork 326
/
ClassInfo.java
2594 lines (2084 loc) · 72.5 KB
/
ClassInfo.java
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
/*
* Copyright (C) 2014, United States Government, as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All rights reserved.
*
* The Java Pathfinder core (jpf-core) platform is licensed under the
* Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package gov.nasa.jpf.vm;
import gov.nasa.jpf.Config;
import gov.nasa.jpf.JPF;
import gov.nasa.jpf.JPFConfigException;
import gov.nasa.jpf.JPFListener;
import gov.nasa.jpf.util.ImmutableList;
import gov.nasa.jpf.util.JPFLogger;
import gov.nasa.jpf.util.LocationSpec;
import gov.nasa.jpf.util.MethodSpec;
import gov.nasa.jpf.util.Misc;
import gov.nasa.jpf.util.OATHash;
import gov.nasa.jpf.util.Source;
import java.io.File;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.logging.Level;
/**
* Describes the VM's view of a java class. Contains descriptions of the
* static and dynamic fields, declaredMethods, and information relevant to the
* class.
*
* Note that ClassInfos / classes have three different construction/initialization steps:
* (1) construction : recursively via ClassLoaderInfo.getResolvedClassInfo -> ClassFileContainer.createClassInfo
* -> ClassInfo ctor -> resolveClass
* this only creates the ClassInfo object, but it is not visible/usable from SUT code yet and hence not
* observable from classLoaded() listeners
* (2) registration : create StaticElementInfo and add it to the respective ClassLoaderInfo statics, then create
* the java.lang.Class companion object in the SUT
* this makes the ClassInfo usable from SUT code
* (3) initialization : execute clinit (if the class has one)
*
* Note that id/uniqueId are NOT set before registration takes place, and registration is not automatically performed since
* listeners/peers might create ClassInfos internally (e.g. for inspection), which should not be visible from the SUT or observable
* by other listeners.
*
* Automatic registration from the ClassInfo ctors would require to pass a ThreadInfo context throughout the whole ClassLoaderInfo/
* ClassFileContainer/ClassInfo chain and could lead to false positives for sharedness based POR, which would record this
* thread as referencing even if this is a listener/peer internal request
*/
public class ClassInfo extends InfoObject implements Iterable<MethodInfo>, GenericSignatureHolder {
//--- ClassInfo states, in chronological order
// note the somewhat strange, decreasing values - >= 0 (=thread-id) means
// we are in clinit
// ideally, we would have a separate RESOLVED state, but (a) this is somewhat
// orthogonal to REGISTERED, and - more importantly - (b) we need the
// superClass instance when initializing our Fields (instance field offsets).
// Doing the field initialization during resolveReferencedClass() seems awkward and
// error prone (there is not much you can do with an unresolved class then)
// not registered or clinit'ed (but cached in loadedClasses)
public static final int UNINITIALIZED = -1;
// 'REGISTERED' simply means 'sei' is set (we have a StaticElementInfo)
// 'INITIALIZING' is any number >=0, which is the thread objRef that executes the clinit
public static final int INITIALIZED = -2;
protected static final String ID_FIELD = "nativeId";
protected static JPFLogger logger = JPF.getLogger("class");
protected static int nClassInfos; // for statistics
protected static Config config;
/**
* ClassLoader that loaded this class.
*/
protected static final ClassLoader thisClassLoader = ClassInfo.class.getClassLoader();
/**
* our abstract factory to createAndInitialize object and class fields
*/
protected static FieldsFactory fieldsFactory;
protected static final FieldInfo[] EMPTY_FIELDINFO_ARRAY = new FieldInfo[0];
protected static final String[] EMPTY_STRING_ARRAY = new String[0];
protected static final String UNINITIALIZED_STRING = "UNINITIALIZED";
protected static final Map<String,MethodInfo> NO_METHODS = Collections.emptyMap();
protected static final Set<ClassInfo> NO_INTERFACES = new HashSet<ClassInfo>();
/**
* support to auto-load listeners from annotations
*/
protected static HashSet<String> autoloadAnnotations;
protected static HashSet<String> autoloaded;
/**
* Name of the class. e.g. "java.lang.String"
* NOTE - this is the expanded name for builtin types, e.g. "int", but NOT
* for arrays, which are for some reason in Ldot notation, e.g. "[Ljava.lang.String;" or "[I"
*/
protected String name;
/** type erased signature of the class. e.g. "Ljava/lang/String;" */
protected String signature;
/** Generic type signatures of the class as per para. 4.4.4 of the revised VM spec */
protected String genericSignature;
/** The classloader that defined (directly loaded) this class */
protected ClassLoaderInfo classLoader;
// various class attributes
protected boolean isClass = true;
protected boolean isWeakReference = false;
protected boolean isObjectClassInfo = false;
protected boolean isStringClassInfo = false;
protected boolean isThreadClassInfo = false;
protected boolean isRefClassInfo = false;
protected boolean isArray = false;
protected boolean isEnum = false;
protected boolean isReferenceArray = false;
protected boolean isAbstract = false;
protected boolean isBuiltin = false;
// that's ultimately where we keep the attributes
// <2do> this is currently quite redundant, but these are used in reflection
protected int modifiers;
protected MethodInfo finalizer = null;
/** type based object attributes (for GC, partial order reduction and
* property checks)
*/
protected int elementInfoAttrs = 0;
/**
* all our declared declaredMethods (we don't flatten, this is not
* a high-performance VM)
*/
protected Map<String, MethodInfo> methods;
/**
* our instance fields.
* Note these are NOT flattened, idx.e. only contain the declared ones
*/
protected FieldInfo[] iFields;
/** the storage size of instances of this class (stored as an int[]) */
protected int instanceDataSize;
/** where in the instance data array (int[]) do our declared fields start */
protected int instanceDataOffset;
/** total number of instance fields (flattened, not only declared ones) */
protected int nInstanceFields;
/**
* our static fields. Again, not flattened
*/
protected FieldInfo[] sFields;
/** the storage size of static fields of this class (stored as an int[]) */
protected int staticDataSize;
/**
* we only set the superClassName upon creation, it is instantiated into
* a ClassInfo by resolveReferencedClass(), which is required to be called before
* we can createAndInitialize objects of this type
*/
protected ClassInfo superClass;
protected String superClassName;
protected String enclosingClassName;
protected String enclosingMethodName;
protected String[] innerClassNames = EMPTY_STRING_ARRAY;
protected BootstrapMethodInfo[] bootstrapMethods;
/** direct ifcs implemented by this class */
protected String[] interfaceNames;
protected Set<ClassInfo> interfaces = new HashSet<ClassInfo>();
/** cache of all interfaceNames (parent interfaceNames and interface parents) - lazy eval */
protected Set<ClassInfo> allInterfaces;
/** Name of the package. */
protected String packageName;
/** this is only set if the classfile has a SourceFile class attribute */
protected String sourceFileName;
/**
* Uniform resource locater for the class file. NOTE: since for builtin classes
* there is no class file assigned is set to the typeName
*/
protected String classFileUrl;
/** from where the corresponding classfile was loaded (if this is not a builtin) */
protected gov.nasa.jpf.vm.ClassFileContainer container;
/**
* a search global numeric id that is only unique within this ClassLoader namespace. Ids are
* computed by the ClassLoaderInfo/Statics implementation during ClassInfo registration
*/
protected int id = -1;
/**
* A search global unique id associate with this class, which is comprised of the classLoader id
* and the (loader-specific) ClassInfo id. This is just a quick way to do search global checks for equality
*
* NOTE - since this is based on the classloader-specific id, it can't be used before the ClassInfo is registered
*/
protected long uniqueId = -1;
/**
* this is the object we use to enter declaredMethods in the underlying VM
* (it replaces Reflection)
*/
protected NativePeer nativePeer;
/** Source file associated with the class.*/
protected Source source;
protected boolean enableAssertions;
/** actions to be taken when an object of this type is gc'ed */
protected ImmutableList<ReleaseAction> releaseActions;
static boolean init (Config config) {
ClassInfo.config = config;
setSourceRoots(config);
//buildBCELModelClassPath(config);
fieldsFactory = config.getEssentialInstance("vm.fields_factory.class",
FieldsFactory.class);
autoloadAnnotations = config.getNonEmptyStringSet("listener.autoload");
if (autoloadAnnotations != null) {
autoloaded = new HashSet<String>();
if (logger.isLoggable(Level.INFO)) {
for (String s : autoloadAnnotations){
logger.info("watching for autoload annotation @" + s);
}
}
}
return true;
}
public static boolean isObjectClassInfo (ClassInfo ci){
return ci.isObjectClassInfo();
}
public static boolean isStringClassInfo (ClassInfo ci){
return ci.isStringClassInfo();
}
//--- initialization interface towards parsers (which might reside in other packages)
protected void setClass(String clsName, String superClsName, int flags, int cpCount) throws ClassParseException {
String parsedName = Types.getClassNameFromTypeName(clsName);
if (name != null && !name.equals(parsedName)){
throw new ClassParseException("wrong class name (expected: " + name + ", found: " + parsedName + ')');
}
name = parsedName;
// the enclosingClassName is set on demand since it requires loading enclosing class candidates
// to verify their innerClass attributes
int i = name.lastIndexOf('.');
packageName = (i > 0) ? name.substring(0, i) : "";
modifiers = flags;
// annotations are interfaces too (not exposed by Modifier)
isClass = ((flags & Modifier.INTERFACE) == 0);
superClassName = superClsName;
}
public void setInnerClassNames(String[] clsNames) {
innerClassNames = clsNames;
}
public void setEnclosingClass (String clsName) {
enclosingClassName = clsName;
}
public void setEnclosingMethod (String mthName){
enclosingMethodName = mthName;
}
public void setInterfaceNames(String[] ifcNames) {
interfaceNames = ifcNames;
}
public void setSourceFile (String fileName){
// prepend if we already know the package
if (packageName.length() > 0) {
// Source will take care of proper separator chars later
sourceFileName = packageName.replace('.', '/') + '/' + fileName;
} else {
sourceFileName = fileName;
}
}
public void setFields(FieldInfo[] fields) {
if (fields == null){
iFields = EMPTY_FIELDINFO_ARRAY;
sFields = EMPTY_FIELDINFO_ARRAY;
} else { // there are fields, we have to tell them apart
int nInstance = 0, nStatic = 0;
for (int i = 0; i < fields.length; i++) {
if (fields[i].isStatic()) {
nStatic++;
} else {
nInstance++;
}
}
FieldInfo[] instanceFields = (nInstance > 0) ? new FieldInfo[nInstance] : EMPTY_FIELDINFO_ARRAY;
FieldInfo[] staticFields = (nStatic > 0) ? new FieldInfo[nStatic] : EMPTY_FIELDINFO_ARRAY;
int iInstance = 0;
int iStatic = 0;
for (int i = 0; i < fields.length; i++) {
FieldInfo fi = fields[i];
if (fi.isStatic()) {
staticFields[iStatic++] = fi;
} else {
instanceFields[iInstance++] = fi;
}
processJPFAnnotations(fi);
}
iFields = instanceFields;
sFields = staticFields;
// we can't link the fields yet because we need the superclasses to be resolved
}
}
protected void setMethod (MethodInfo mi){
mi.linkToClass(this);
methods.put( mi.getUniqueName(), mi);
processJPFAnnotations(mi);
}
public void setMethods (MethodInfo[] newMethods) {
if (newMethods != null && newMethods.length > 0) {
methods = new LinkedHashMap<String, MethodInfo>();
for (int i = 0; i < newMethods.length; i++) {
setMethod( newMethods[i]);
}
}
}
protected void processJPFAttrAnnotation(InfoObject infoObj){
AnnotationInfo ai = infoObj.getAnnotation("gov.nasa.jpf.annotation.JPFAttribute");
if (ai != null){
String[] attrTypes = ai.getValueAsStringArray();
if (attrTypes != null){
ClassLoader loader = config.getClassLoader();
for (String clsName : attrTypes){
try {
Class<?> attrCls = loader.loadClass(clsName);
Object attr = attrCls.newInstance(); // needs to have a default ctor
infoObj.addAttr(attr);
} catch (ClassNotFoundException cnfx){
logger.warning("attribute class not found: " + clsName);
} catch (IllegalAccessException iax){
logger.warning("attribute class has no public default ctor: " + clsName);
} catch (InstantiationException ix){
logger.warning("attribute class has no default ctor: " + clsName);
}
}
}
}
}
protected void processNoJPFExecutionAnnotation(InfoObject infoObj) {
AnnotationInfo ai = infoObj.getAnnotation("gov.nasa.jpf.annotation.NoJPFExecution");
if (ai != null) {
infoObj.addAttr(NoJPFExec.SINGLETON);
}
}
protected void processJPFAnnotations(InfoObject infoObj) {
processJPFAttrAnnotation(infoObj);
processNoJPFExecutionAnnotation(infoObj);
}
public AnnotationInfo getResolvedAnnotationInfo (String typeName){
return classLoader.getResolvedAnnotationInfo( typeName);
}
@Override
public void setAnnotations(AnnotationInfo[] annotations) {
this.annotations = annotations;
}
//--- end initialization interface
//--- the overridden annotation accessors (we need these because of inherited superclass annotations)
// note that we don't flatten annotations anymore, assuming the prevalent query will be getAnnotation(name)
@Override
public boolean hasAnnotations(){
if (annotations.length > 0){
return true;
}
for (ClassInfo ci = superClass; ci != null; ci = ci.superClass){
AnnotationInfo[] a = ci.annotations;
for (int j=0; j<a.length; j++){
if (a[j].isInherited()){
return true;
}
}
}
return false;
}
/**
* return all annotations, which includes the ones inherited from our superclasses
* NOTE - this is not very efficient
*/
@Override
public AnnotationInfo[] getAnnotations() {
int nAnnotations = annotations.length;
for (ClassInfo ci = superClass; ci != null; ci = ci.superClass){
AnnotationInfo[] a = ci.annotations;
for (int i=0; i<a.length; i++){
if (a[i].isInherited()){
nAnnotations++;
}
}
}
AnnotationInfo[] allAnnotations = new AnnotationInfo[nAnnotations];
System.arraycopy(annotations, 0, allAnnotations, 0, annotations.length);
int idx=annotations.length;
for (ClassInfo ci = superClass; ci != null; ci = ci.superClass){
AnnotationInfo[] a = ci.annotations;
for (int i=0; i<a.length; i++){
if (a[i].isInherited()){
allAnnotations[idx++] = a[i];
}
}
}
return allAnnotations;
}
@Override
public AnnotationInfo getAnnotation (String annotationName){
AnnotationInfo[] a = annotations;
for (int i=0; i<a.length; i++){
if (a[i].getName().equals(annotationName)){
return a[i];
}
}
for (ClassInfo ci = superClass; ci != null; ci = ci.superClass){
a = ci.annotations;
for (int i=0; i<a.length; i++){
AnnotationInfo ai = a[i];
if (ai.getName().equals(annotationName) && ai.isInherited()){
return ai;
}
}
}
return null;
}
protected ClassInfo (String name, ClassLoaderInfo cli, String classFileUrl){
nClassInfos++;
this.name = name;
this.classLoader = cli;
this.classFileUrl = classFileUrl;
this.methods = NO_METHODS; // yet
// rest has to be initialized by concrete ctor, which should call resolveAndLink(parser)
}
/**
* the initialization part that has to happen once we have super, fields, methods and annotations
* NOTE - this has to be called by concrete ctors after parsing class files
*/
protected void resolveAndLink () throws ClassParseException {
//--- these might get streamlined
isStringClassInfo = isStringClassInfo0();
isThreadClassInfo = isThreadClassInfo0();
isObjectClassInfo = isObjectClassInfo0();
isRefClassInfo = isRefClassInfo0();
// isWeakReference = isWeakReference0();
isAbstract = (modifiers & Modifier.ABSTRACT) != 0;
// isEnum = isEnum0();
finalizer = getFinalizer0();
resolveClass(); // takes care of super classes and interfaces
// Used to enter native methods (in the host VM).
// This needs to be initialized AFTER we get our MethodInfos, since it does a reverse lookup to determine which
// ones are handled by the peer (by means of setting MethodInfo attributes)
nativePeer = loadNativePeer();
checkUnresolvedNativeMethods();
linkFields(); // computes field offsets
setAssertionStatus();
processJPFConfigAnnotation();
processJPFAnnotations(this);
loadAnnotationListeners();
}
protected ClassInfo(){
nClassInfos++;
// for explicit subclass initialization
}
/**
* ClassInfo ctor used for builtin types (arrays and primitive types)
* idx.e. classes we don't have class files for
*/
protected ClassInfo (String builtinClassName, ClassLoaderInfo classLoader) {
nClassInfos++;
this.classLoader = classLoader;
isArray = (builtinClassName.charAt(0) == '[');
isReferenceArray = isArray && (builtinClassName.endsWith(";") || builtinClassName.charAt(1) == '[');
isBuiltin = true;
name = builtinClassName;
logger.log(Level.FINE, "generating builtin class: %1$s", name);
packageName = ""; // builtin classes don't reside in java.lang !
sourceFileName = null;
source = null;
genericSignature = "";
// no fields
iFields = EMPTY_FIELDINFO_ARRAY;
sFields = EMPTY_FIELDINFO_ARRAY;
if (isArray) {
if(classLoader.isSystemClassLoader()) {
superClass = ((SystemClassLoaderInfo)classLoader).getObjectClassInfo();
} else {
superClass = ClassLoaderInfo.getCurrentSystemClassLoader().getObjectClassInfo();
}
interfaceNames = loadArrayInterfaces();
methods = loadArrayMethods();
} else {
superClass = null; // strange, but true, a 'no object' class
interfaceNames = loadBuiltinInterfaces(name);
methods = loadBuiltinMethods(name);
}
enableAssertions = true; // doesn't really matter - no code associated
classFileUrl = name;
// no fields or declaredMethods, so we don't have to link/resolve anything
}
public static int getNumberOfLoadedClasses(){
return nClassInfos;
}
//--- the VM type specific methods
// <2do> those should be abstract
protected void setAnnotationValueGetterCode (MethodInfo pmi, FieldInfo fi){
// to be overridden by VM specific class
}
protected void setDirectCallCode (MethodInfo miCallee, MethodInfo miStub){
// to be overridden by VM specific class
}
protected void setLambdaDirectCallCode (MethodInfo miDirectCall, BootstrapMethodInfo bootstrapMethod){
// to be overridden by VM specific class
}
protected void setNativeCallCode (NativeMethodInfo miNative){
// to be overridden by VM specific class
}
protected void setRunStartCode (MethodInfo miStub, MethodInfo miRun){
// to be overridden by VM specific class
}
/**
* createAndInitialize a fully synthetic implementation of an Annotation proxy
*/
protected ClassInfo (ClassInfo annotationCls, String name, ClassLoaderInfo classLoader, String url) {
this.classLoader = classLoader;
this.name = name;
isClass = true;
//superClass = objectClassInfo;
superClass = ClassLoaderInfo.getSystemResolvedClassInfo("gov.nasa.jpf.AnnotationProxyBase");
interfaceNames = new String[]{ annotationCls.name };
packageName = annotationCls.packageName;
sourceFileName = annotationCls.sourceFileName;
genericSignature = annotationCls.genericSignature;
sFields = new FieldInfo[0]; // none
staticDataSize = 0;
methods = new HashMap<String, MethodInfo>();
iFields = new FieldInfo[annotationCls.methods.size()];
nInstanceFields = iFields.length;
// all accessor declaredMethods of ours make it into iField/method combinations
int idx = 0;
int off = 0; // no super class
for (MethodInfo mi : annotationCls.getDeclaredMethodInfos()) {
String mname = mi.getName();
String mtype = mi.getReturnType();
String genericSignature = mi.getGenericSignature();
// create and initialize an instance field for it
FieldInfo fi = FieldInfo.create(mname, mtype, 0);
fi.linkToClass(this, idx, off);
fi.setGenericSignature(genericSignature);
iFields[idx++] = fi;
off += fi.getStorageSize();
MethodInfo pmi = new MethodInfo(this, mname, mi.getSignature(), Modifier.PUBLIC, 1, 2);
pmi.setGenericSignature(genericSignature);
setAnnotationValueGetterCode( pmi, fi);
methods.put(pmi.getUniqueName(), pmi);
}
instanceDataSize = computeInstanceDataSize();
instanceDataOffset = 0;
classFileUrl = url;
linkFields();
}
//used to create synthetic classes that implement functional interfaces
protected ClassInfo createFuncObjClassInfo (BootstrapMethodInfo bootstrapMethod, String name, String samUniqueName, String[] fieldTypesName) {
return null;
}
protected ClassInfo (ClassInfo funcInterface, BootstrapMethodInfo bootstrapMethod, String name, String[] fieldTypesName) {
ClassInfo enclosingClass = bootstrapMethod.enclosingClass;
this.classLoader = enclosingClass.classLoader;
this.name = name;
isClass = true;
superClassName = "java.lang.Object";
interfaceNames = new String[]{ funcInterface.name };
packageName = enclosingClass.getPackageName();
// creating fields used to capture free variables
int n = fieldTypesName.length;
iFields = new FieldInfo[n];
nInstanceFields = n;
sFields = new FieldInfo[0];
staticDataSize = 0;
int idx = 0;
int off = 0; // no super class
int i = 0;
for(String type: fieldTypesName) {
FieldInfo fi = FieldInfo.create("arg" + i++, type, 0);
fi.linkToClass(this, idx, off);
iFields[idx++] = fi;
off += fi.getStorageSize();
}
linkFields();
}
// since id and hence uniqueId are not set before this class is registered, we can't use them
@Override
public int hashCode() {
return OATHash.hash(name.hashCode(), classLoader.hashCode());
}
@Override
public boolean equals (Object o) {
if (o instanceof ClassInfo) {
ClassInfo other = (ClassInfo)o;
if (classLoader == other.classLoader) {
// beware of ClassInfos that are not registered yet - in this case we have to equals names
if (name.equals(other.name)) {
return true;
}
}
}
return false;
}
protected String computeSourceFileName(){
return name.replace('.', '/') + ".java";
}
protected void checkUnresolvedNativeMethods(){
for (MethodInfo mi : methods.values()){
if (mi.isUnresolvedNativeMethod()){
NativeMethodInfo nmi = new NativeMethodInfo(mi, null, nativePeer);
nmi.replace(mi);
}
}
}
protected void processJPFConfigAnnotation() {
AnnotationInfo ai = getAnnotation("gov.nasa.jpf.annotation.JPFConfig");
if (ai != null) {
for (String s : ai.getValueAsStringArray()) {
config.parse(s);
}
}
}
protected void loadAnnotationListeners () {
if (autoloadAnnotations != null) {
autoloadListeners(annotations); // class annotations
for (int i=0; i<sFields.length; i++) {
autoloadListeners(sFields[i].getAnnotations());
}
for (int i=0; i<iFields.length; i++) {
autoloadListeners(iFields[i].getAnnotations());
}
// method annotations are checked during method loading
// (to avoid extra iteration)
}
}
void autoloadListeners(AnnotationInfo[] annos) {
if ((annos != null) && (autoloadAnnotations != null)) {
for (AnnotationInfo ai : annos) {
String aName = ai.getName();
if (autoloadAnnotations.contains(aName)) {
if (!autoloaded.contains(aName)) {
autoloaded.add(aName);
String key = "listener." + aName;
String defClsName = aName + "Checker";
try {
JPFListener listener = config.getInstance(key, JPFListener.class, defClsName);
JPF jpf = VM.getVM().getJPF(); // <2do> that's a BAD access path
jpf.addUniqueTypeListener(listener);
if (logger.isLoggable(Level.INFO)){
logger.info("autoload annotation listener: @", aName, " => ", listener.getClass().getName());
}
} catch (JPFConfigException cx) {
logger.warning("no autoload listener class for annotation " + aName +
" : " + cx.getMessage());
autoloadAnnotations.remove(aName);
}
}
}
}
if (autoloadAnnotations.isEmpty()) {
autoloadAnnotations = null;
}
}
}
protected NativePeer loadNativePeer(){
return NativePeer.getNativePeer(this);
}
/**
* Returns the class loader that
*/
public ClassLoaderInfo getClassLoaderInfo() {
return classLoader;
}
/**
* the container this is stored in
*/
public Statics getStatics() {
return classLoader.getStatics();
}
/**
* required by InfoObject interface
*/
public ClassInfo getClassInfo() {
return this;
}
protected void setAssertionStatus() {
if(isInitialized()) {
return;
} else {
enableAssertions = classLoader.desiredAssertionStatus(name);
}
}
boolean getAssertionStatus () {
return enableAssertions;
}
public boolean desiredAssertionStatus() {
return classLoader.desiredAssertionStatus(name);
}
@Override
public String getGenericSignature() {
return genericSignature;
}
@Override
public void setGenericSignature(String sig){
genericSignature = sig;
}
public boolean isArray () {
return isArray;
}
public boolean isEnum () {
return isEnum;
}
public boolean isAbstract() {
return isAbstract;
}
public boolean isBuiltin(){
return isBuiltin;
}
public boolean isInterface() {
return ((modifiers & Modifier.INTERFACE) != 0);
}
public boolean isReferenceArray () {
return isReferenceArray;
}
public boolean isObjectClassInfo() {
return isObjectClassInfo;
}
public boolean isStringClassInfo() {
return isStringClassInfo;
}
public boolean isThreadClassInfo() {
return isThreadClassInfo;
}
protected void checkNoClinitInitialization(){
if (!isInitialized()){
ThreadInfo ti = ThreadInfo.getCurrentThread();
registerClass(ti);
setInitialized(); // we might want to check if there is a clinit
}
}
protected ClassInfo createAnnotationProxy (String proxyName){
// to be overridden by VM specific ClassInfos
return null;
}
public ClassInfo getAnnotationProxy (){
// <2do> test if this is a annotation ClassInfo
checkNoClinitInitialization(); // annotation classes don't have clinits
ClassInfo ciProxy = classLoader.getResolvedAnnotationProxy(this);
ciProxy.checkNoClinitInitialization();
return ciProxy;
}
/**
public static ClassInfo getAnnotationProxy (ClassInfo ciAnnotation){
ThreadInfo ti = ThreadInfo.getCurrentThread();
// make sure the annotationCls is initialized (no code there)
if (!ciAnnotation.isInitialized()) {
ciAnnotation.registerClass(ti);
ciAnnotation.setInitialized(); // no clinit
}
String url = computeProxyUrl(ciAnnotation);
ClassInfo ci = null; // getOriginalClassInfo(url);
if (ci == null){
String cname = ciAnnotation.getName() + "$Proxy";
ci = new ClassInfo(ciAnnotation, cname, ciAnnotation.classLoader, url);
ciAnnotation.classLoader.addResolvedClass(ci);
if (!ci.isInitialized()){
ci.registerClass(ti);
ci.setInitialized();
}
}
return ci;
}
**/
public boolean areAssertionsEnabled() {
return enableAssertions;
}
public boolean hasInstanceFields () {
return (instanceDataSize > 0);
}
public ElementInfo getClassObject(){
StaticElementInfo sei = getStaticElementInfo();
if (sei != null){
int objref = sei.getClassObjectRef();
return VM.getVM().getElementInfo(objref);
}
return null;
}
public ElementInfo getModifiableClassObject(){
StaticElementInfo sei = getStaticElementInfo();
if (sei != null){
int objref = sei.getClassObjectRef();
return VM.getVM().getModifiableElementInfo(objref);
}
return null;
}
public int getClassObjectRef () {
StaticElementInfo sei = getStaticElementInfo();