comparison src/share/vm/graal/graalVmIds.hpp @ 2890:c23d45daff9b

Renamed cpp/hpp file directory.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 08 Jun 2011 13:40:25 +0200
parents src/share/vm/c1x/graalVmIds.hpp@2fb867285938
children f00918f35c7f
comparison
equal deleted inserted replaced
2889:2fb867285938 2890:c23d45daff9b
1 /*
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 #include "memory/allocation.hpp"
25 #include "utilities/growableArray.hpp"
26 #include "oops/oop.hpp"
27 #include "runtime/handles.hpp"
28 #include "runtime/thread.hpp"
29 #include "classfile/javaClasses.hpp"
30 #include "runtime/jniHandles.hpp"
31
32 class VmIds : public AllStatic {
33
34 private:
35 static GrowableArray<address>* _stubs;
36 static GrowableArray<jobject>* _localHandles;
37
38 static oop getObject(jlong id);
39
40 public:
41 // these constants needs to have the same values as the one in HotSpotProxy.java
42 static const jlong STUB = 0x100000000000000LL; // address
43 static const jlong METHOD = 0x200000000000000LL; // methodOop
44 static const jlong CLASS = 0x300000000000000LL; // klassOop
45 static const jlong CONSTANT_POOL = 0x500000000000000LL; // constantPoolOop
46 static const jlong CONSTANT = 0x600000000000000LL; // oop
47 static const jlong TYPE_MASK = 0xf00000000000000LL;
48 static const jlong DUMMY_CONSTANT = 0x6ffffffffffffffLL;
49
50 // Initializes the VmIds for a compilation, by creating the arrays
51 static void initializeObjects();
52 // Cleans up after a compilation, by deallocating the arrays
53 static void cleanupLocalObjects();
54
55 // Adds a stub address, and returns the corresponding vmId (which is of type STUB)
56 static jlong addStub(address stub);
57
58 // Adds an object, and returns the corresponding vmId (with the given type)
59 static jlong add(Handle obj, jlong type);
60
61 // Adds an object, and returns the corresponding vmId (the type of which is determined by the template parameter)
62 template <typename T> static jlong add(T obj);
63
64
65 // Returns the stub address with the given vmId
66 static address getStub(jlong id);
67 // Returns the stub address with the given vmId taken from a java.lang.Long
68 static address getStub(oop id);
69
70 // Returns the object with the given id, the return type is defined by the template parameter (which must correspond to the actual type of the vmId)
71 template <typename T> static T get(jlong id);
72
73
74 // Helper function to convert a symbol to a java.lang.String object
75 template <typename T> static T toString(Symbol* symbol, TRAPS);
76
77 // Helper function to convert a java.lang.String object to a symbol (this will return NULL if the symbol doesn't exist in the system)
78 static Symbol* toSymbol(jstring string);
79
80 // Helper function to get the contents of a java.lang.Long
81 static jlong getBoxedLong(oop obj);
82 };
83
84
85 template <> inline jlong VmIds::add<methodOop>(methodOop obj){
86 assert(obj != NULL, "trying to add NULL<methodOop>");
87 assert(obj->is_method(), "trying to add mistyped object");
88 return add(Handle(obj), METHOD);
89 }
90 template <> inline jlong VmIds::add<klassOop>(klassOop obj) {
91 assert(obj != NULL, "trying to add NULL<klassOop>");
92 assert(obj->is_klass(), "trying to add mistyped object");
93 return add(Handle(obj), CLASS);
94 }
95 template <> inline jlong VmIds::add<constantPoolOop>(constantPoolOop obj) {
96 assert(obj != NULL, "trying to add NULL<constantPoolOop>");
97 assert(obj->is_constantPool(), "trying to add mistyped object");
98 return add(Handle(obj), CONSTANT_POOL);
99 }
100 template <> inline jlong VmIds::add<oop>(oop obj) {
101 assert(obj != NULL, "trying to add NULL<oop>");
102 assert(obj->is_oop(), "trying to add mistyped object");
103 return add(Handle(obj), CONSTANT);
104 }
105
106
107 template <> inline methodOop VmIds::get<methodOop>(jlong id){
108 assert((id & TYPE_MASK) == METHOD, "METHOD expected");
109 assert(getObject(id)->is_method(), "methodOop expected");
110 return (methodOop)getObject(id);
111 }
112 template <> inline klassOop VmIds::get<klassOop>(jlong id) {
113 assert((id & TYPE_MASK) == CLASS, "CLASS expected");
114 assert(getObject(id)->is_klass(), "klassOop expected");
115 return (klassOop)getObject(id);
116 }
117 template <> inline constantPoolOop VmIds::get<constantPoolOop>(jlong id) {
118 assert((id & TYPE_MASK) == CONSTANT_POOL, "CONSTANT_POOL expected");
119 assert(getObject(id)->is_constantPool(), "constantPoolOop expected");
120 return (constantPoolOop)getObject(id);
121 }
122 template <> inline oop VmIds::get<oop>(jlong id) {
123 assert((id & TYPE_MASK) == CONSTANT, "CONSTANT expected");
124 assert(getObject(id)->is_oop(true), "oop expected");
125 return (oop)getObject(id);
126 }
127
128 inline address VmIds::getStub(oop obj) {
129 return getStub(getBoxedLong(obj));
130 }
131
132 template <> inline Handle VmIds::toString<Handle>(Symbol* symbol, TRAPS) {
133 return java_lang_String::create_from_symbol(symbol, THREAD);
134 }
135 template <> inline oop VmIds::toString<oop>(Symbol* symbol, TRAPS) {
136 return toString<Handle>(symbol, THREAD)();
137 }
138 template <> inline jstring VmIds::toString<jstring>(Symbol* symbol, TRAPS) {
139 return (jstring)JNIHandles::make_local(toString<oop>(symbol, THREAD));
140 }
141 template <> inline jobject VmIds::toString<jobject>(Symbol* symbol, TRAPS) {
142 return JNIHandles::make_local(toString<oop>(symbol, THREAD));
143 }
144
145 inline Symbol* VmIds::toSymbol(jstring string) {
146 return java_lang_String::as_symbol_or_null(JNIHandles::resolve(string));
147 }
148
149 inline jlong VmIds::getBoxedLong(oop obj) {
150 assert(obj->is_oop(true), "cannot unbox null or non-oop");
151 return obj->long_field(java_lang_boxing_object::value_offset_in_bytes(T_LONG));
152 }