annotate agent/src/share/classes/sun/jvm/hotspot/utilities/soql/JSJavaField.java @ 17467:55fb97c4c58d hs25-b65

8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013 Summary: Copyright year updated for files modified during 2013 Reviewed-by: twisti, iveresov
author mikael
date Tue, 24 Dec 2013 11:48:39 -0800
parents c18cbe5936b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved.
0
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 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.utilities.soql;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 public class JSJavaField extends DefaultScriptObject {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 private static final int FIELD_NAME = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 private static final int FIELD_SIGNATURE = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 private static final int FIELD_HOLDER = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private static final int FIELD_IS_PRIVATE = 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private static final int FIELD_IS_PUBLIC = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private static final int FIELD_IS_PROTECTED = 5;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 private static final int FIELD_IS_PACKAGE_PRIVATE = 6;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 private static final int FIELD_IS_STATIC = 7;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 private static final int FIELD_IS_FINAL = 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private static final int FIELD_IS_VOLATILE = 9;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private static final int FIELD_IS_TRANSIENT = 10;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 private static final int FIELD_IS_SYNTHETIC = 11;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 private static final int FIELD_UNDEFINED = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 public JSJavaField(Field f, JSJavaFactory fac) {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 this.field = f;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 this.factory = fac;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 public Object get(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 int fieldID = getFieldID(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
53 switch (fieldID) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 case FIELD_NAME:
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return field.getID().getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
56 case FIELD_SIGNATURE:
a61af66fc99e Initial load
duke
parents:
diff changeset
57 return field.getSignature().asString();
a61af66fc99e Initial load
duke
parents:
diff changeset
58 case FIELD_HOLDER:
a61af66fc99e Initial load
duke
parents:
diff changeset
59 return getFieldHolder();
a61af66fc99e Initial load
duke
parents:
diff changeset
60 case FIELD_IS_PRIVATE:
a61af66fc99e Initial load
duke
parents:
diff changeset
61 return Boolean.valueOf(field.isPrivate());
a61af66fc99e Initial load
duke
parents:
diff changeset
62 case FIELD_IS_PUBLIC:
a61af66fc99e Initial load
duke
parents:
diff changeset
63 return Boolean.valueOf(field.isPublic());
a61af66fc99e Initial load
duke
parents:
diff changeset
64 case FIELD_IS_PROTECTED:
a61af66fc99e Initial load
duke
parents:
diff changeset
65 return Boolean.valueOf(field.isProtected());
a61af66fc99e Initial load
duke
parents:
diff changeset
66 case FIELD_IS_PACKAGE_PRIVATE:
a61af66fc99e Initial load
duke
parents:
diff changeset
67 return Boolean.valueOf(field.isPackagePrivate());
a61af66fc99e Initial load
duke
parents:
diff changeset
68 case FIELD_IS_STATIC:
a61af66fc99e Initial load
duke
parents:
diff changeset
69 return Boolean.valueOf(field.isStatic());
a61af66fc99e Initial load
duke
parents:
diff changeset
70 case FIELD_IS_FINAL:
a61af66fc99e Initial load
duke
parents:
diff changeset
71 return Boolean.valueOf(field.isFinal());
a61af66fc99e Initial load
duke
parents:
diff changeset
72 case FIELD_IS_VOLATILE:
a61af66fc99e Initial load
duke
parents:
diff changeset
73 return Boolean.valueOf(field.isVolatile());
a61af66fc99e Initial load
duke
parents:
diff changeset
74 case FIELD_IS_TRANSIENT:
a61af66fc99e Initial load
duke
parents:
diff changeset
75 return Boolean.valueOf(field.isTransient());
a61af66fc99e Initial load
duke
parents:
diff changeset
76 case FIELD_IS_SYNTHETIC:
a61af66fc99e Initial load
duke
parents:
diff changeset
77 return Boolean.valueOf(field.isSynthetic());
a61af66fc99e Initial load
duke
parents:
diff changeset
78 case FIELD_UNDEFINED:
a61af66fc99e Initial load
duke
parents:
diff changeset
79 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
80 return super.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 public Object[] getIds() {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 Object[] fieldNames = fields.keySet().toArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
86 Object[] superFields = super.getIds();
a61af66fc99e Initial load
duke
parents:
diff changeset
87 Object[] res = new Object[fieldNames.length + superFields.length];
a61af66fc99e Initial load
duke
parents:
diff changeset
88 System.arraycopy(fieldNames, 0, res, 0, fieldNames.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 System.arraycopy(superFields, 0, res, fieldNames.length, superFields.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 public boolean has(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 if (getFieldID(name) != FIELD_UNDEFINED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 return super.has(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 public void put(String name, Object value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 if (getFieldID(name) == FIELD_UNDEFINED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 super.put(name, value);
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 public boolean equals(Object o) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 if (o == null || !(o instanceof JSJavaField)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 JSJavaField other = (JSJavaField) o;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 return field.equals(other.field);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 public int hashCode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 return field.hashCode();
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 public String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
122 buf.append("Field ");
a61af66fc99e Initial load
duke
parents:
diff changeset
123 buf.append(field.getFieldHolder().getName().asString().replace('/', '.'));
a61af66fc99e Initial load
duke
parents:
diff changeset
124 buf.append('.');
a61af66fc99e Initial load
duke
parents:
diff changeset
125 buf.append(field.getID().getName());
a61af66fc99e Initial load
duke
parents:
diff changeset
126 return buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 //-- Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
130 private JSJavaObject getFieldHolder() {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 return factory.newJSJavaKlass(field.getFieldHolder()).getJSJavaClass();
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 private static Map fields = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
135 private static void addField(String name, int fieldId) {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 fields.put(name, new Integer(fieldId));
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 private static int getFieldID(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 Integer res = (Integer) fields.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 return (res != null)? res.intValue() : FIELD_UNDEFINED;
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 addField("name", FIELD_NAME);
a61af66fc99e Initial load
duke
parents:
diff changeset
146 addField("signature", FIELD_SIGNATURE);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 addField("holder", FIELD_HOLDER);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 addField("isPrivate", FIELD_IS_PRIVATE);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 addField("isPublic", FIELD_IS_PUBLIC);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 addField("isProtected", FIELD_IS_PROTECTED);
a61af66fc99e Initial load
duke
parents:
diff changeset
151 addField("isPackagePrivate", FIELD_IS_PACKAGE_PRIVATE);
a61af66fc99e Initial load
duke
parents:
diff changeset
152 addField("isStatic", FIELD_IS_STATIC);
a61af66fc99e Initial load
duke
parents:
diff changeset
153 addField("isFinal", FIELD_IS_FINAL);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 addField("isVolatile", FIELD_IS_VOLATILE);
a61af66fc99e Initial load
duke
parents:
diff changeset
155 addField("isTransient", FIELD_IS_TRANSIENT);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 addField("isSynthetic", FIELD_IS_SYNTHETIC);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 private final Field field;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 private final JSJavaFactory factory;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }