annotate agent/src/share/classes/sun/jvm/hotspot/utilities/soql/MapScriptObject.java @ 818:b109e761e927

6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14 Summary: Disable escape analysis when jvmti/debugger is used. Add support for EA ibto SA. Reviewed-by: never
author kvn
date Tue, 09 Jun 2009 16:19:10 -0700
parents a61af66fc99e
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 */
a61af66fc99e Initial load
duke
parents:
diff changeset
23
a61af66fc99e Initial load
duke
parents:
diff changeset
24 package sun.jvm.hotspot.utilities.soql;
a61af66fc99e Initial load
duke
parents:
diff changeset
25
a61af66fc99e Initial load
duke
parents:
diff changeset
26 import java.util.Map;
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.util.HashMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.util.Collections;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.lang.reflect.Method;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.lang.reflect.Constructor;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import javax.script.Invocable;
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
34 * Simple implementation of ScriptObject interface
a61af66fc99e Initial load
duke
parents:
diff changeset
35 * with property storage backed by a Map. This class
a61af66fc99e Initial load
duke
parents:
diff changeset
36 * can be extended to override any of the methods, in
a61af66fc99e Initial load
duke
parents:
diff changeset
37 * particular to add "function" valued properties.
a61af66fc99e Initial load
duke
parents:
diff changeset
38 */
a61af66fc99e Initial load
duke
parents:
diff changeset
39 public class MapScriptObject implements ScriptObject {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // map to store the properties
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private Map map;
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 public MapScriptObject() {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 this(new HashMap());
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 public MapScriptObject(Map map) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // make it synchronized
a61af66fc99e Initial load
duke
parents:
diff changeset
49 this.map = Collections.synchronizedMap(map);
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 public Object[] getIds() {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 return map.keySet().toArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 public Object get(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 if (has(name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 return map.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 return UNDEFINED;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 public Object get(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 if (has(index)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 Object key = Integer.valueOf(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 return map.get(key);
a61af66fc99e Initial load
duke
parents:
diff changeset
68 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 return UNDEFINED;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 public void put(String name, Object value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 map.put(name, value);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 public void put(int index, Object value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 map.put(Integer.valueOf(index), value);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 public boolean has(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 return map.containsKey(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 public boolean has(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 return map.containsKey(Integer.valueOf(index));
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 public boolean delete(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 if (map.containsKey(name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 map.remove(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 public boolean delete(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 Object key = Integer.valueOf(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
100 if (map.containsKey(key)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 map.remove(key);
a61af66fc99e Initial load
duke
parents:
diff changeset
102 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // add a function valued property that invokes given Method
a61af66fc99e Initial load
duke
parents:
diff changeset
109 protected void putFunction(Object target, Method method) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 putFunction(target, method, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // add a function valued property that invokes given Method
a61af66fc99e Initial load
duke
parents:
diff changeset
114 protected void putFunction(Object target, Method method, boolean wrapArgs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 map.put(method.getName(), new MethodCallable(target, method, wrapArgs));
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // add a function valued property that invokes given script function
a61af66fc99e Initial load
duke
parents:
diff changeset
119 protected void putFunction(Object target, String name, Invocable invocable) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 map.put(name, new InvocableCallable(target, name, invocable));
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }