KickJava   Java API By Example, From Geeks To Geeks.

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


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.Object.
22  *
23  * @author Feng Qian
24  */

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

40   public void simulateMethod(SootMethod method,
41                  ReferenceVariable thisVar,
42                  ReferenceVariable returnVar,
43                  ReferenceVariable params[]){
44     String JavaDoc subSignature = method.getSubSignature();
45
46     /* Driver */
47
48     if (subSignature.equals("java.lang.Class getClass()")) {
49       java_lang_Object_getClass(method, thisVar, returnVar, params);
50       return;
51
52     } else if (subSignature.equals("java.lang.Object clone()")) {
53       java_lang_Object_clone(method, thisVar, returnVar, params);
54       return;
55      
56     } else {
57       defaultMethod(method, thisVar, returnVar, params);
58       return;
59     }
60   }
61
62   /*********************** java.lang.Object *********************/
63   /**
64    * The return variable is assigned an abstract object represneting
65    * all classes (UnknowClassObject) from environment.
66    *
67    * public final native java.lang.Class getClass();
68    */

69   public void java_lang_Object_getClass(SootMethod method,
70                            ReferenceVariable thisVar,
71                            ReferenceVariable returnVar,
72                            ReferenceVariable params[]) {
73     helper.assignObjectTo(returnVar, Environment.v().getClassObject());
74   }
75
76   /**
77    * Creates and returns a copy of this object. The precise meaning of
78    * "copy" may depend on the class of the object. The general intent
79    * is that, for any object x, the expression:
80    *
81    * x.clone() != x
82    *
83    * will be true, and that the expression:
84    *
85    * x.clone().getClass() == x.getClass()
86    *
87    * will be true, but these are not absolute requirements. While it is
88    * typically the case that:
89    *
90    * x.clone().equals(x)
91    *
92    * will be true, this is not an absolute requirement. Copying an
93    * object will typically entail creating a new instance of its
94    * class, but it also may require copying of internal data
95    * structures as well. No constructors are called.
96    *
97    * NOTE: it may raise an exception, the decision of cloning made by
98    * analysis by implementing the ReferneceVariable.cloneObject()
99    * method.
100    *
101    * protected native java.lang.Object clone()
102    * throws java.lang.CloneNotSupported
103    */

104   public void java_lang_Object_clone(SootMethod method,
105                         ReferenceVariable thisVar,
106                         ReferenceVariable returnVar,
107                         ReferenceVariable params[]) {
108     ReferenceVariable newVar = helper.cloneObject(thisVar);
109     helper.assign(returnVar, newVar);
110   }
111
112   /**
113    * Following methods have NO side effect
114    *
115    * private static native void registerNatives();
116    * public native int hashCode();
117    * public final native void notify();
118    * public final native void notifyAll();
119    * public final native void wait(long)
120    * throws java.lang.InterruptedException;
121    */

122
123 }
124
Popular Tags