01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 2003 Feng Qian
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * 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.String
22: *
23: * @author Feng Qian
24: * @author <XXX>
25: */package soot.jimple.toolkits.pointer.nativemethods;
26:
27: import soot.*;
28: import soot.jimple.toolkits.pointer.representations.*;
29: import soot.jimple.toolkits.pointer.util.*;
30:
31: public class JavaLangStringNative extends NativeMethodClass {
32: public JavaLangStringNative(NativeHelper helper) {
33: super (helper);
34: }
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 this Var, ReferenceVariable returnVar,
43: ReferenceVariable params[]) {
44:
45: String subSignature = method.getSubSignature();
46:
47: if (subSignature.equals("java.lang.String intern()")) {
48: java_lang_String_intern(method, this Var, returnVar, params);
49: return;
50:
51: } else {
52: defaultMethod(method, this Var, returnVar, params);
53: return;
54:
55: }
56: }
57:
58: /************************** java.lang.String ***********************/
59: /**
60: * Returns a canonical representation for the string object. A pool
61: * of strings, initially empty, is maintained privately by the class
62: * String.
63: *
64: * When the intern method is invoked, if the pool already contains a
65: * * string equal to this String object as determined by the *
66: * equals(Object) method, then the string from the pool is *
67: * returned. Otherwise, this String object is added to the pool and
68: * a * reference to this String object is returned.
69: *
70: * It follows that for any two strings s and t,
71: * s.intern() == t.intern()
72: * is true if and only if s.equals(t) is true.
73: *
74: * All literal strings and string-valued constant expressions are *
75: * interned. String literals are defined in Section 3.10.5 of the Java *
76: * Language Specification Returns: a string that has the same
77: * contents * as this string, but is guaranteed to be from a pool of
78: * unique * strings.
79: *
80: * Side Effect: from the description, we can see, it is tricky to
81: * know the side effect of this native method.
82: * Take a conservative way to handle this.
83: *
84: * It may be @return = this;
85: * pool = this;
86: *
87: * why should we care about String in points-to analysis?
88: *
89: * public native java.lang.String intern();
90: */
91: public void java_lang_String_intern(SootMethod method,
92: ReferenceVariable this Var, ReferenceVariable returnVar,
93: ReferenceVariable params[]) {
94: helper.assignObjectTo(returnVar, Environment.v()
95: .getStringObject());
96: }
97: }
|