View Javadoc

1   // Interface.java, created Fri Apr  5 18:36:41 2002 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.ClassLib.sun15_win32;
5   
6   import java.util.Iterator;
7   import joeq.Class.PrimordialClassLoader;
8   import joeq.Class.jq_Class;
9   import joeq.Class.jq_InstanceField;
10  import joeq.Class.jq_StaticField;
11  import joeq.ClassLib.ClassLibInterface;
12  import joeq.Main.jq;
13  import joeq.Runtime.ObjectTraverser;
14  import jwutil.collections.AppendIterator;
15  
16  /*
17   * @author  John Whaley <jwhaley@alum.mit.edu>
18   * @version $Id: Interface.java 2075 2004-12-10 19:04:43Z joewhaley $
19   */
20  public class Interface extends joeq.ClassLib.sun142_win32.Interface {
21  
22      /*** Creates new Interface */
23      public Interface() {}
24  
25      public Iterator getImplementationClassDescs(joeq.UTF.Utf8 desc) {
26          if (ClassLibInterface.USE_JOEQ_CLASSLIB &&
27                  (desc.toString().startsWith("Ljava/") ||
28                   desc.toString().startsWith("Lsun/misc/"))) {
29              joeq.UTF.Utf8 u = joeq.UTF.Utf8.get("Ljoeq/ClassLib/sun15_win32/"+desc.toString().substring(1));
30              return new AppendIterator(super.getImplementationClassDescs(desc),
31                                        java.util.Collections.singleton(u).iterator());
32          }
33          return super.getImplementationClassDescs(desc);
34      }
35      
36      public ObjectTraverser getObjectTraverser() {
37          return sun15_win32ObjectTraverser.INSTANCE;
38      }
39      
40      public static class sun15_win32ObjectTraverser extends sun142_win32ObjectTraverser {
41          public static sun15_win32ObjectTraverser INSTANCE = new sun15_win32ObjectTraverser();
42          protected sun15_win32ObjectTraverser() {}
43          public void initialize() {
44              super.initialize();
45              
46              jq_Class k;
47  
48              // jdk1.5 caches name string.
49              k = (jq_Class) PrimordialClassLoader.getJavaLangClass();
50              nullInstanceFields.add(k.getOrCreateInstanceField("name", "Ljava/lang/String;"));
51              
52              // jdk1.5 caches field accessors.
53              k = (jq_Class) PrimordialClassLoader.getJavaLangReflectField();
54              nullInstanceFields.add(k.getOrCreateInstanceField("fieldAccessor", "Lsun/reflect/FieldAccessor;"));
55              nullInstanceFields.add(k.getOrCreateInstanceField("overrideFieldAccessor", "Lsun/reflect/FieldAccessor;"));
56              
57              // crashes on reflective access.
58              k = (jq_Class) PrimordialClassLoader.loader.getOrCreateBSType("Lsun/reflect/UnsafeStaticFieldAccessorImpl;");
59              nullInstanceFields.add(k.getOrCreateInstanceField("base", "Ljava/lang/Object;"));
60  
61              // leads to sun.security.rsa junk
62              k = (jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("Lsun/security/jca/Providers;");
63              nullStaticFields.add(k.getOrCreateStaticField("threadLists", "Ljava/lang/ThreadLocal;"));
64              nullStaticFields.add(k.getOrCreateStaticField("providerList", "Lsun/security/jca/ProviderList;"));
65  
66              // leads to sun.security.provider.certpath junk
67              k = (jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("Lsun/net/www/protocol/jar/JarFileFactory;");
68              nullStaticFields.add(k.getOrCreateStaticField("fileCache", "Ljava/util/HashMap;"));
69              nullStaticFields.add(k.getOrCreateStaticField("urlCache", "Ljava/util/HashMap;"));
70              
71              // we need to reinitialize in/out/err on startup.
72              if (jq.on_vm_startup != null) {
73                  Object[] args = { } ;
74                  k = (jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("Ljava/io/FileDescriptor;");
75                  joeq.Class.jq_Method init_fd = k.getOrCreateStaticMethod("init", "()V");
76                  joeq.Bootstrap.MethodInvocation mi = new joeq.Bootstrap.MethodInvocation(init_fd, args);
77                  jq.on_vm_startup.add(mi);
78                  System.out.println("Added call to reinitialize in/out/err file descriptors on joeq startup: "+mi);
79              }
80          }
81          
82          /*
83          public java.lang.Object mapInstanceField(java.lang.Object o, joeq.Class.jq_InstanceField f) {
84              if (o instanceof FileDescriptor) {
85                  String fieldName = f.getName().toString();
86                  if (fieldName.equals("fd")) {
87                      if (o == FileDescriptor.in) return Integer.valueOf(0);
88                      if (o == FileDescriptor.out) return Integer.valueOf(1);
89                      if (o == FileDescriptor.err) return Integer.valueOf(2);
90                      System.out.println("File descriptor will be stale: "+o);
91                  }
92              }
93              return super.mapInstanceField(o, f);
94          }
95          */
96          
97          public static final jq_StaticField valueOffsetField;
98          
99          static {
100             jq_Class k = (jq_Class) PrimordialClassLoader.loader.getOrCreateBSType("Ljava/util/concurrent/atomic/AtomicLong;");
101             valueOffsetField = k.getOrCreateStaticField("valueOffset", "J");
102         }
103         
104         public java.lang.Object mapStaticField(jq_StaticField f) {
105             // valueOffset is the offset of the "value" field in AtomicLong
106             if (f == valueOffsetField) {
107                 jq_Class k = (jq_Class) PrimordialClassLoader.loader.getOrCreateBSType("Ljava/util/concurrent/atomic/AtomicLong;");
108                 k.prepare();
109                 int offset = ((jq_InstanceField) k.getDeclaredMember("value", "J")).getOffset();
110                 return new Long(offset);
111             }
112             return super.mapStaticField(f);
113         }
114     }
115 }