KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > pointer > nativemethods > JavaLangClassLoaderNative


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Feng Qian
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /**
21  * Simulates the native method side effects in class java.lang.ClassLoader
22  *
23  * @author Feng Qian
24  * @author <XXX>
25  */

26
27 package soot.jimple.toolkits.pointer.nativemethods;
28
29 import soot.*;
30 import soot.jimple.toolkits.pointer.representations.*;
31 import soot.jimple.toolkits.pointer.util.*;
32
33 public class JavaLangClassLoaderNative extends NativeMethodClass {
34     public JavaLangClassLoaderNative( NativeHelper helper ) { super(helper); }
35
36   /**
37    * Implements the abstract method simulateMethod.
38    * It distributes the request to the corresponding methods
39    * by signatures.
40    */

41   public void simulateMethod(SootMethod method,
42                  ReferenceVariable thisVar,
43                  ReferenceVariable returnVar,
44                  ReferenceVariable params[]){
45
46     String JavaDoc subSignature = method.getSubSignature();
47
48     if (subSignature.equals("java.lang.Class defineClass0(java.lang.String,byte[],int,int,java.lang.security.ProtectionDomain)")){
49       java_lang_ClassLoader_defineClass0(method, thisVar, returnVar, params);
50       return;
51
52     } else if (subSignature.equals("java.lang.Class findBootstrapClass(java.lang.String)")){
53       java_lang_ClassLoader_findBootstrapClass(method, thisVar,
54                            returnVar, params);
55       return;
56
57     } else if (subSignature.equals("java.lang.Class findLoadedClass(java.lang.String)")){
58       java_lang_ClassLoader_findLoadedClass(method, thisVar,
59                         returnVar, params);
60       return;
61
62     } else if (subSignature.equals("java.lang.ClassLoader getCallerClassLoader()")){
63       java_lang_ClassLoader_getCallerClassLoader(method, thisVar,
64                          returnVar, params);
65       return;
66       
67     } else {
68       defaultMethod(method, thisVar, returnVar, params);
69       return;
70
71     }
72   }
73
74   /************************** java.lang.ClassLoader ******************/
75   /**
76    * Converts an array of bytes into an instance of class
77    * Class. Before the Class can be used it must be resolved.
78    *
79    * NOTE: an object representing an class object.
80    * To be conservative, the side-effect of this method will
81    * return an abstract reference points to all possible class object
82    * in current analysis environment.
83    *
84    * private native
85    * java.lang.Class defineClass0(java.lang.String,
86    * byte[],
87    * int,
88    * int,
89    * java.security.ProtectionDomain);
90    */

91   public
92     void java_lang_ClassLoader_defineClass0(SootMethod method,
93                         ReferenceVariable thisVar,
94                         ReferenceVariable returnVar,
95                         ReferenceVariable params[]){
96     helper.assignObjectTo(returnVar, Environment.v().getClassObject());
97   }
98
99   /**
100    * NOTE: undocumented, finding the bootstrap class
101    *
102    * Assuming all classes
103    *
104    * private native
105    * java.lang.Class findBootstrapClass(java.lang.String)
106    * throws java.lang.ClassNotFoundException;
107    */

108   public
109     void java_lang_ClassLoader_findBootstrapClass(
110                      SootMethod method,
111                                          ReferenceVariable thisVar,
112                      ReferenceVariable returnVar,
113                      ReferenceVariable params[]) {
114     helper.assignObjectTo(returnVar, Environment.v().getClassObject());
115   }
116
117   /**
118    * Finds the class with the given name if it had been previously
119    * loaded through this class loader.
120    *
121    * NOTE: assuming all classes.
122    *
123    * protected final native java.lang.Class findLoadedClass(java.lang.String);
124    */

125   public
126     void java_lang_ClassLoader_findLoadedClass(SootMethod method,
127                            ReferenceVariable thisVar,
128                            ReferenceVariable returnVar,
129                            ReferenceVariable params[]) {
130     helper.assignObjectTo(returnVar, Environment.v().getClassObject());
131   }
132
133   /**
134    * Returns a variable pointing to the only class loader
135    *
136    * static native java.lang.ClassLoader getCallerClassLoader();
137    */

138   public
139     void java_lang_ClassLoader_getCallerClassLoader(
140                     SootMethod method,
141                     ReferenceVariable thisVar,
142                     ReferenceVariable returnVar,
143                     ReferenceVariable params[]) {
144     helper.assignObjectTo(returnVar, Environment.v().getClassLoaderObject());
145   }
146
147   /**
148    * NO side effects.
149    *
150    * Assuming that resolving a class has not effect on the class load
151    * and class object
152    *
153    * private native void resolveClass0(java.lang.Class);
154    */

155 }
156
Popular Tags