comparison src/share/vm/graal/graalCompiler.cpp @ 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/graalCompiler.cpp@2fb867285938
children 75a99b4f1c98
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 "precompiled.hpp"
25 #include "c1x/c1x_Compiler.hpp"
26 #include "c1x/c1x_JavaAccess.hpp"
27 #include "c1x/c1x_VMExits.hpp"
28 #include "c1x/c1x_VMEntries.hpp"
29 #include "c1x/c1x_VmIds.hpp"
30 #include "c1/c1_Runtime1.hpp"
31 #include "runtime/arguments.hpp"
32
33 C1XCompiler* C1XCompiler::_instance = NULL;
34
35 C1XCompiler::C1XCompiler() {
36 _initialized = false;
37 assert(_instance == NULL, "only one instance allowed");
38 _instance = this;
39 }
40
41 // Initialization
42 void C1XCompiler::initialize() {
43 if (_initialized) return;
44 CompilerThread* THREAD = CompilerThread::current();
45 _initialized = true;
46 TRACE_C1X_1("C1XCompiler::initialize");
47
48 VmIds::initializeObjects();
49
50 initialize_buffer_blob();
51 Runtime1::initialize(THREAD->get_buffer_blob());
52
53 JNIEnv *env = ((JavaThread *) Thread::current())->jni_environment();
54 jclass klass = env->FindClass("com/oracle/max/graal/runtime/VMEntriesNative");
55 if (klass == NULL) {
56 tty->print_cr("c1x VMEntries class not found");
57 vm_abort(false);
58 }
59 env->RegisterNatives(klass, VMEntries_methods, VMEntries_methods_count());
60
61 {
62 VM_ENTRY_MARK;
63 check_pending_exception("Could not register natives");
64 }
65
66 c1x_compute_offsets();
67
68 {
69 VM_ENTRY_MARK;
70 HandleMark hm;
71 VMExits::setDefaultOptions();
72 for (int i = 0; i < Arguments::num_c1x_args(); ++i) {
73 const char* arg = Arguments::c1x_args_array()[i];
74 Handle option = java_lang_String::create_from_str(arg, THREAD);
75 jboolean result = VMExits::setOption(option);
76 if (!result) {
77 tty->print_cr("Invalid option for C1X!");
78 vm_abort(false);
79 }
80 }
81
82 VMExits::initializeCompiler();
83 }
84 }
85
86 void C1XCompiler::initialize_buffer_blob() {
87
88 CompilerThread* THREAD = CompilerThread::current();
89 if (THREAD->get_buffer_blob() == NULL) {
90 // setup CodeBuffer. Preallocate a BufferBlob of size
91 // NMethodSizeLimit plus some extra space for constants.
92 int code_buffer_size = Compilation::desired_max_code_buffer_size() +
93 Compilation::desired_max_constant_size();
94 BufferBlob* blob = BufferBlob::create("C1X temporary CodeBuffer",
95 code_buffer_size);
96 guarantee(blob != NULL, "must create code buffer");
97 THREAD->set_buffer_blob(blob);
98 }
99 }
100
101 // Compilation entry point for methods
102 void C1XCompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) {
103 initialize();
104 VM_ENTRY_MARK;
105 ResourceMark rm;
106 HandleMark hm;
107
108 initialize_buffer_blob();
109 VmIds::initializeObjects();
110
111 TRACE_C1X_2("C1XCompiler::compile_method");
112
113 CompilerThread::current()->set_compiling(true);
114 methodOop method = (methodOop) target->get_oop();
115 VMExits::compileMethod(VmIds::add<methodOop>(method), VmIds::toString<Handle>(method->name(), THREAD), entry_bci);
116 CompilerThread::current()->set_compiling(false);
117
118 VmIds::cleanupLocalObjects();
119 TRACE_C1X_2("C1XCompiler::compile_method exit");
120 }
121
122 // Print compilation timers and statistics
123 void C1XCompiler::print_timers() {
124 TRACE_C1X_1("C1XCompiler::print_timers");
125 }
126
127 oop C1XCompiler::get_RiType(ciType *type, KlassHandle accessor, TRAPS) {
128 if (type->is_loaded()) {
129 if (type->is_primitive_type()) {
130 return VMExits::createRiTypePrimitive((int) type->basic_type(), THREAD);
131 }
132 KlassHandle klass = (klassOop) type->get_oop();
133 Handle name = VmIds::toString<Handle>(klass->name(), THREAD);
134 return createHotSpotTypeResolved(klass, name, CHECK_NULL);
135 } else {
136 Symbol* name = ((ciKlass *) type)->name()->get_symbol();
137 return VMExits::createRiTypeUnresolved(VmIds::toString<Handle>(name, THREAD), THREAD);
138 }
139 }
140
141 oop C1XCompiler::get_RiField(ciField *field, ciInstanceKlass* accessor_klass, KlassHandle accessor, Bytecodes::Code byteCode, TRAPS) {
142 bool will_link = field->will_link_from_vm(accessor_klass, byteCode);
143 int offset = (field->holder()->is_loaded() && will_link) ? field->offset() : -1;
144 Handle field_name = VmIds::toString<Handle>(field->name()->get_symbol(), CHECK_0);
145 Handle field_holder = get_RiType(field->holder(), accessor, CHECK_0);
146 Handle field_type = get_RiType(field->type(), accessor, CHECK_0);
147 int flags = field->flags().as_int();
148 return VMExits::createRiField(field_holder, field_name, field_type, offset, flags, THREAD);
149 }
150
151 oop C1XCompiler::createHotSpotTypeResolved(KlassHandle klass, Handle name, TRAPS) {
152 if (klass->c1x_mirror() != NULL) {
153 return klass->c1x_mirror();
154 }
155
156 instanceKlass::cast(HotSpotTypeResolved::klass())->initialize(CHECK_NULL);
157 Handle obj = instanceKlass::cast(HotSpotTypeResolved::klass())->allocate_instance(CHECK_NULL);
158 assert(obj() != NULL, "must succeed in allocating instance");
159
160 HotSpotTypeResolved::set_compiler(obj, VMExits::compilerInstance()());
161
162 if (klass->oop_is_instance()) {
163 instanceKlass* ik = (instanceKlass*)klass()->klass_part();
164 Handle full_name = java_lang_String::create_from_str(ik->signature_name(), CHECK_NULL);
165 HotSpotType::set_name(obj, full_name());
166 } else {
167 HotSpotType::set_name(obj, name());
168 }
169
170 HotSpotTypeResolved::set_javaMirror(obj, klass->java_mirror());
171 HotSpotTypeResolved::set_simpleName(obj, name());
172 HotSpotTypeResolved::set_accessFlags(obj, klass->access_flags().as_int());
173 HotSpotTypeResolved::set_isInterface(obj, klass->is_interface());
174 HotSpotTypeResolved::set_isInstanceClass(obj, klass->oop_is_instance());
175
176 if (klass->oop_is_javaArray()) {
177 HotSpotTypeResolved::set_isArrayClass(obj, true);
178 HotSpotTypeResolved::set_componentType(obj, NULL);
179 } else {
180 HotSpotTypeResolved::set_isArrayClass(obj, false);
181 HotSpotTypeResolved::set_componentType(obj, NULL);
182 HotSpotTypeResolved::set_isInitialized(obj, instanceKlass::cast(klass())->is_initialized());
183 HotSpotTypeResolved::set_instanceSize(obj, instanceKlass::cast(klass())->size_helper() * HeapWordSize);
184 HotSpotTypeResolved::set_hasFinalizer(obj, klass->has_finalizer());
185 }
186
187 // TODO replace these with correct values
188 HotSpotTypeResolved::set_hasSubclass(obj, false);
189 HotSpotTypeResolved::set_hasFinalizableSubclass(obj, false);
190
191 klass->set_c1x_mirror(obj());
192
193 return obj();
194 }
195
196 BasicType C1XCompiler::kindToBasicType(jchar ch) {
197 switch(ch) {
198 case 'z': return T_BOOLEAN;
199 case 'b': return T_BYTE;
200 case 's': return T_SHORT;
201 case 'c': return T_CHAR;
202 case 'i': return T_INT;
203 case 'f': return T_FLOAT;
204 case 'l': return T_LONG;
205 case 'd': return T_DOUBLE;
206 case 'a': return T_OBJECT;
207 case 'r': return T_ADDRESS;
208 case '-': return T_ILLEGAL;
209 default:
210 fatal(err_msg("unexpected CiKind: %c", ch));
211 break;
212 }
213 return T_ILLEGAL;
214 }
215