Mercurial > hg > graal-jvmci-8
comparison src/share/vm/c1x/c1x_Compiler.cpp @ 1423:760213a60e8b
* rewrite of the code installation
* partial support for safepoints
* macro-based CiTargetMethod interface
* code stub support
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Mon, 16 Aug 2010 18:59:36 -0700 |
parents | 3483ec571caf |
children | 98fffb304868 |
comparison
equal
deleted
inserted
replaced
1422:3483ec571caf | 1423:760213a60e8b |
---|---|
29 | 29 |
30 // Initialization | 30 // Initialization |
31 void C1XCompiler::initialize() { | 31 void C1XCompiler::initialize() { |
32 if (_initialized) return; | 32 if (_initialized) return; |
33 _initialized = true; | 33 _initialized = true; |
34 TRACE_C1X_1("initialize"); | 34 TRACE_C1X_1("initialize"); |
35 | 35 |
36 JNIEnv *env = ((JavaThread *)Thread::current())->jni_environment(); | 36 JNIEnv *env = ((JavaThread *)Thread::current())->jni_environment(); |
37 jclass klass = env->FindClass("com/sun/hotspot/c1x/VMEntriesNative"); | 37 jclass klass = env->FindClass("com/sun/hotspot/c1x/VMEntriesNative"); |
38 assert(klass != NULL, "c1x VMEntries class not found"); | 38 assert(klass != NULL, "c1x VMEntries class not found"); |
39 env->RegisterNatives(klass, VMEntries_methods, VMEntries_methods_count() ); | 39 env->RegisterNatives(klass, VMEntries_methods, VMEntries_methods_count() ); |
40 | 40 |
41 check_pending_exception("Could not register natives"); | 41 check_pending_exception("Could not register natives"); |
42 | |
43 compute_offsets(); | |
42 } | 44 } |
43 | 45 |
44 // Compilation entry point for methods | 46 // Compilation entry point for methods |
45 void C1XCompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) { | 47 void C1XCompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) { |
46 initialize(); | 48 initialize(); |
48 VM_ENTRY_MARK; | 50 VM_ENTRY_MARK; |
49 | 51 |
50 ResourceMark rm; | 52 ResourceMark rm; |
51 HandleMark hm; | 53 HandleMark hm; |
52 | 54 |
55 C1XObjects::initializeObjects(); | |
56 | |
53 CompilerThread::current()->set_compiling(true); | 57 CompilerThread::current()->set_compiling(true); |
54 VMExits::compileMethod((methodOop)target->get_oop(), entry_bci); | 58 methodOop method = (methodOop)target->get_oop(); |
59 VMExits::compileMethod(C1XObjects::add<methodOop>(method), C1XObjects::toString<Handle>(method->name(), THREAD), entry_bci); | |
55 CompilerThread::current()->set_compiling(false); | 60 CompilerThread::current()->set_compiling(false); |
61 | |
62 C1XObjects::cleanupLocalObjects(); | |
56 } | 63 } |
57 | 64 |
58 // Print compilation timers and statistics | 65 // Print compilation timers and statistics |
59 void C1XCompiler::print_timers() { | 66 void C1XCompiler::print_timers() { |
60 TRACE_C1X_1("print_timers"); | 67 TRACE_C1X_1("print_timers"); |
61 } | 68 } |
62 | 69 |
63 oop C1XCompiler::get_RiType(oop name, klassOop accessingType, TRAPS) { | |
64 symbolOop klass = java_lang_String::as_symbol_or_null(name); | |
65 | |
66 if (klass == vmSymbols::byte_signature()) { | |
67 return VMExits::createRiTypePrimitive((int)T_BYTE, THREAD); | |
68 } else if (klass == vmSymbols::char_signature()) { | |
69 return VMExits::createRiTypePrimitive((int)T_CHAR, THREAD); | |
70 } else if (klass == vmSymbols::double_signature()) { | |
71 return VMExits::createRiTypePrimitive((int)T_DOUBLE, THREAD); | |
72 } else if (klass == vmSymbols::float_signature()) { | |
73 return VMExits::createRiTypePrimitive((int)T_FLOAT, THREAD); | |
74 } else if (klass == vmSymbols::int_signature()) { | |
75 return VMExits::createRiTypePrimitive((int)T_INT, THREAD); | |
76 } else if (klass == vmSymbols::long_signature()) { | |
77 return VMExits::createRiTypePrimitive((int)T_LONG, THREAD); | |
78 } else if (klass == vmSymbols::bool_signature()) { | |
79 return VMExits::createRiTypePrimitive((int)T_BOOLEAN, THREAD); | |
80 } | |
81 Handle classloader; | |
82 if (accessingType != NULL) { | |
83 classloader = accessingType->klass_part()->class_loader(); | |
84 } | |
85 klassOop resolved_type = SystemDictionary::resolve_or_null(klass, classloader, accessingType->klass_part()->protection_domain(), Thread::current()); | |
86 if (resolved_type != NULL) { | |
87 return VMExits::createRiType(resolved_type, THREAD); | |
88 } else { | |
89 return VMExits::createRiTypeUnresolved(klass, accessingType, THREAD); | |
90 } | |
91 } | |
92 | |
93 oop C1XCompiler::get_RiType(ciType *type, klassOop accessor, TRAPS) { | 70 oop C1XCompiler::get_RiType(ciType *type, klassOop accessor, TRAPS) { |
94 if (type->is_loaded()) { | 71 if (type->is_loaded()) { |
95 if (type->is_primitive_type()) { | 72 if (type->is_primitive_type()) { |
96 return VMExits::createRiTypePrimitive((int)type->basic_type(), THREAD); | 73 return VMExits::createRiTypePrimitive((int)type->basic_type(), THREAD); |
97 } | 74 } |
98 return VMExits::createRiType((klassOop)type->get_oop(), THREAD); | 75 klassOop klass = (klassOop)type->get_oop(); |
76 return VMExits::createRiType(C1XObjects::add<klassOop>(klass), C1XObjects::toString<Handle>(klass->klass_part()->name(), THREAD), THREAD); | |
99 } else { | 77 } else { |
100 return VMExits::createRiTypeUnresolved(((ciKlass *)type)->name()->get_symbolOop(), accessor, THREAD); | 78 symbolOop name = ((ciKlass *)type)->name()->get_symbolOop(); |
79 return VMExits::createRiTypeUnresolved(C1XObjects::toString<Handle>(name, THREAD), C1XObjects::add<klassOop>(accessor), THREAD); | |
101 } | 80 } |
102 } | 81 } |
103 | 82 |
104 oop C1XCompiler::get_RiField(ciField *field, TRAPS) { | 83 oop C1XCompiler::get_RiField(ciField *field, TRAPS) { |
105 oop field_holder = get_RiType(field->holder(), NULL, CHECK_0); | 84 oop field_holder = get_RiType(field->holder(), NULL, CHECK_0); |
106 oop field_type = get_RiType(field->type(), NULL, CHECK_0); | 85 oop field_type = get_RiType(field->type(), NULL, CHECK_0); |
107 symbolOop field_name = field->name()->get_symbolOop(); | 86 Handle field_name = C1XObjects::toString<Handle>(field->name()->get_symbolOop(), CHECK_0); |
108 int offset = field->offset(); | 87 int offset = field->offset(); |
109 | 88 |
110 // TODO: implement caching | 89 // TODO: implement caching |
111 return VMExits::createRiField(field_holder, field_name, field_type, offset, THREAD); | 90 return VMExits::createRiField(field_holder, field_name, field_type, offset, THREAD); |
112 } | 91 } |
113 | 92 |
114 /* | 93 // C1XObjects implementation |
115 oop C1XCompiler::get_RiMethod(ciMethod *method, TRAPS) { | 94 |
116 methodOop m = (methodOop)method->get_oop(); | 95 GrowableArray<address>* C1XObjects::_stubs = NULL; |
117 return get_RiMethod(m, THREAD); | 96 GrowableArray<jobject>* C1XObjects::_localHandles = NULL; |
97 | |
98 void C1XObjects::initializeObjects() { | |
99 if (_stubs == NULL) { | |
100 assert(_localHandles == NULL, "inconsistent state"); | |
101 _stubs = new(ResourceObj::C_HEAP) GrowableArray<address>(64, true); | |
102 _localHandles = new(ResourceObj::C_HEAP) GrowableArray<jobject>(64, true); | |
103 } | |
104 assert(_localHandles->length() == 0, "invalid state"); | |
118 } | 105 } |
119 | 106 |
120 oop C1XCompiler::get_RiMethod(methodOop m, TRAPS) { | 107 void C1XObjects::cleanupLocalObjects() { |
121 // TODO: implement caching | 108 for (int i=0; i<_localHandles->length(); i++) { |
122 return VMExits::createRiMethod(m, THREAD); | 109 JNIHandles::destroy_global(_localHandles->at(i)); |
110 } | |
111 _localHandles->clear(); | |
112 } | |
113 | |
114 jlong C1XObjects::addStub(address stub) { | |
115 assert(!_stubs->contains(stub), "duplicate stub"); | |
116 return _stubs->append(stub) | STUB; | |
117 } | |
118 | |
119 jlong C1XObjects::add(Handle obj, CompilerObjectType type) { | |
120 assert(!obj.is_null(), "cannot add NULL handle"); | |
121 int idx = -1; | |
122 for (int i=0; i<_localHandles->length(); i++) | |
123 if (JNIHandles::resolve_non_null(_localHandles->at(i)) == obj()) { | |
124 idx = i; | |
125 break; | |
126 } | |
127 if (idx = -1) { | |
128 if (JavaThread::current()->thread_state() == _thread_in_vm) { | |
129 idx = _localHandles->append(JNIHandles::make_global(obj)); | |
130 } else { | |
131 VM_ENTRY_MARK; | |
132 idx = _localHandles->append(JNIHandles::make_global(obj)); | |
133 } | |
134 } | |
135 return idx | type; | |
136 } | |
137 | |
138 address C1XObjects::getStub(jlong id) { | |
139 assert((id & TYPE_MASK) == STUB, "wrong id type, STUB expected"); | |
140 assert((id & ~TYPE_MASK) >= 0 && (id & ~TYPE_MASK) < _stubs->length(), "STUB index out of bounds"); | |
141 return _stubs->at(id & ~TYPE_MASK); | |
142 } | |
143 | |
144 oop C1XObjects::getObject(jlong id) { | |
145 assert((id & TYPE_MASK) != STUB, "wrong id type"); | |
146 assert((id & ~TYPE_MASK) >= 0 && (id & ~TYPE_MASK) < _localHandles->length(), "index out of bounds"); | |
147 return JNIHandles::resolve_non_null(_localHandles->at(id & ~TYPE_MASK)); | |
123 } | 148 } |
124 | 149 |
125 | 150 |
126 oop C1XCompiler::get_RiType(klassOop klass, TRAPS) { | 151 static void compute_offset(int &dest_offset, klassOop klass_oop, const char* name, const char* signature) { |
127 // TODO: implement caching | 152 symbolOop name_symbol = SymbolTable::probe(name, strlen(name)); |
128 return VMExits::createRiType(klass, THREAD); | 153 symbolOop signature_symbol = SymbolTable::probe(signature, strlen(signature)); |
154 assert(name_symbol != NULL, "symbol not found - class layout changed?"); | |
155 assert(signature_symbol != NULL, "symbol not found - class layout changed?"); | |
156 | |
157 instanceKlass* ik = instanceKlass::cast(klass_oop); | |
158 fieldDescriptor fd; | |
159 if (!ik->find_field(name_symbol, signature_symbol, &fd)) { | |
160 ResourceMark rm; | |
161 tty->print_cr("Invalid layout of %s at %s", ik->external_name(), name_symbol->as_C_string()); | |
162 fatal("Invalid layout of preloaded class"); | |
163 } | |
164 dest_offset = fd.offset(); | |
129 } | 165 } |
130 | 166 |
131 oop C1XCompiler::get_RiConstantPool(constantPoolOop cp, TRAPS) { | 167 // create the compute_class |
132 // TODO: implement caching | 168 #define START_CLASS(name) { klassOop k = SystemDictionary::name##_klass(); |
133 return VMExits::createRiConstantPool(cp, THREAD); | 169 |
170 #define END_CLASS } | |
171 | |
172 #define FIELD(klass, name, signature) compute_offset(klass::_##name##_offset, k, #name, signature); | |
173 #define CHAR_FIELD(klass, name) FIELD(klass, name, "C") | |
174 #define INT_FIELD(klass, name) FIELD(klass, name, "I") | |
175 #define LONG_FIELD(klass, name) FIELD(klass, name, "J") | |
176 #define OOP_FIELD(klass, name, signature) FIELD(klass, name, signature) | |
177 | |
178 | |
179 void C1XCompiler::compute_offsets() { | |
180 COMPILER_CLASSES_DO(START_CLASS, END_CLASS, CHAR_FIELD, INT_FIELD, LONG_FIELD, OOP_FIELD) | |
134 } | 181 } |
135 | 182 |
136 oop C1XCompiler::get_unresolved_RiType(symbolOop klass, klassOop accessingType, TRAPS) { | 183 #define EMPTY0 |
137 // TODO: implement caching | 184 #define EMPTY1(x) |
138 return VMExits::createRiTypeUnresolved(klass, accessingType, THREAD); | 185 #define EMPTY2(x,y) |
139 } | 186 #define FIELD2(klass, name) int klass::_##name##_offset = 0; |
140 */ | 187 #define FIELD3(klass, name, sig) FIELD2(klass, name) |
141 | 188 |
142 // conversion internal objects -> reflected objects | 189 COMPILER_CLASSES_DO(EMPTY1, EMPTY0, FIELD2, FIELD2, FIELD2, FIELD3) |
143 | |
144 oop C1XObjects::getReflectedMethod(methodOop method, TRAPS) { | |
145 if (method->is_initializer()) { | |
146 return Reflection::new_constructor(method, CHECK_0); | |
147 } else { | |
148 return Reflection::new_method(method, UseNewReflection, false, CHECK_0); | |
149 } | |
150 } | |
151 | |
152 oop C1XObjects::getReflectedClass(klassOop klass) { | |
153 return klass->klass_part()->java_mirror(); | |
154 } | |
155 | |
156 oop C1XObjects::getReflectedSymbol(symbolOop symbol, TRAPS) { | |
157 return java_lang_String::create_from_symbol(symbol, THREAD)(); | |
158 } | |
159 | |
160 // conversion reflected objects -> internal objects | |
161 | |
162 methodOop C1XObjects::getInternalMethod(oop method) { | |
163 // copied from JNIEnv::FromReflectedMethod | |
164 oop mirror = NULL; | |
165 int slot = 0; | |
166 | |
167 if (method->klass() == SystemDictionary::reflect_Constructor_klass()) { | |
168 mirror = java_lang_reflect_Constructor::clazz(method); | |
169 slot = java_lang_reflect_Constructor::slot(method); | |
170 } else { | |
171 assert(method->klass() == SystemDictionary::reflect_Method_klass(), "wrong type"); | |
172 mirror = java_lang_reflect_Method::clazz(method); | |
173 slot = java_lang_reflect_Method::slot(method); | |
174 } | |
175 klassOop k = java_lang_Class::as_klassOop(mirror); | |
176 return instanceKlass::cast(k)->method_with_idnum(slot); | |
177 } | |
178 | |
179 klassOop C1XObjects::getInternalClass(oop klass) { | |
180 return java_lang_Class::as_klassOop(klass); | |
181 } | |
182 | |
183 symbolOop C1XObjects::getInternalSymbol(oop string) { | |
184 return java_lang_String::as_symbol_or_null(string); | |
185 } | |
186 | 190 |
187 | 191 |
188 | 192 |
193 | |
194 |