annotate src/share/vm/opto/c2compiler.cpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children b789bcaf2dd9
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 1999-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
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_c2compiler.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 volatile int C2Compiler::_runtimes = uninitialized;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // register information defined by ADLC
a61af66fc99e Initial load
duke
parents:
diff changeset
32 extern const char register_save_policy[];
a61af66fc99e Initial load
duke
parents:
diff changeset
33 extern const int register_save_type[];
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 const char* C2Compiler::retry_no_subsuming_loads() {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 return "retry without subsuming loads";
a61af66fc99e Initial load
duke
parents:
diff changeset
37 }
a61af66fc99e Initial load
duke
parents:
diff changeset
38 void C2Compiler::initialize_runtime() {
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // Check assumptions used while running ADLC
a61af66fc99e Initial load
duke
parents:
diff changeset
41 Compile::adlc_verification();
a61af66fc99e Initial load
duke
parents:
diff changeset
42 assert(REG_COUNT <= ConcreteRegisterImpl::number_of_registers, "incompatible register counts");
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 for (int i = 0; i < ConcreteRegisterImpl::number_of_registers ; i++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 OptoReg::vm2opto[i] = OptoReg::Bad;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(REG_COUNT); i = OptoReg::add(i,1) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 VMReg r = OptoReg::as_VMReg(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
50 if (r->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 OptoReg::vm2opto[r->value()] = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 }
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // Check that runtime and architecture description agree on callee-saved-floats
a61af66fc99e Initial load
duke
parents:
diff changeset
56 bool callee_saved_floats = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(_last_Mach_Reg); i = OptoReg::add(i,1) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // Is there a callee-saved float or double?
a61af66fc99e Initial load
duke
parents:
diff changeset
59 if( register_save_policy[i] == 'E' /* callee-saved */ &&
a61af66fc99e Initial load
duke
parents:
diff changeset
60 (register_save_type[i] == Op_RegF || register_save_type[i] == Op_RegD) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 callee_saved_floats = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 DEBUG_ONLY( Node::init_NodeProperty(); )
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 Compile::pd_compiler2_init();
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 CompilerThread* thread = CompilerThread::current();
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 HandleMark handle_mark(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 OptoRuntime::generate(thread->env());
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 void C2Compiler::initialize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // This method can only be called once per C2Compiler object
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // The first compiler thread that gets here will initialize the
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // small amount of global state (and runtime stubs) that c2 needs.
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // There is a race possible once at startup and then we're fine
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // Note that this is being called from a compiler thread not the
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // main startup thread.
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 if (_runtimes != initialized) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 initialize_runtimes( initialize_runtime, &_runtimes);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // Mark this compiler object as ready to roll
a61af66fc99e Initial load
duke
parents:
diff changeset
94 mark_initialized();
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 void C2Compiler::compile_method(ciEnv* env,
a61af66fc99e Initial load
duke
parents:
diff changeset
98 ciMethod* target,
a61af66fc99e Initial load
duke
parents:
diff changeset
99 int entry_bci) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 if (!is_initialized()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103 bool subsume_loads = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 while (!env->failing()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // Attempt to compile while subsuming loads into machine instructions.
a61af66fc99e Initial load
duke
parents:
diff changeset
106 Compile C(env, this, target, entry_bci, subsume_loads);
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // Check result and retry if appropriate.
a61af66fc99e Initial load
duke
parents:
diff changeset
109 if (C.failure_reason() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 if (C.failure_reason_is(retry_no_subsuming_loads())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 assert(subsume_loads, "must make progress");
a61af66fc99e Initial load
duke
parents:
diff changeset
112 subsume_loads = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 continue; // retry
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // Pass any other failure reason up to the ciEnv.
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // Note that serious, irreversible failures are already logged
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // on the ciEnv via env->record_method_not_compilable().
a61af66fc99e Initial load
duke
parents:
diff changeset
118 env->record_failure(C.failure_reason());
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // No retry; just break the loop.
a61af66fc99e Initial load
duke
parents:
diff changeset
122 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 void C2Compiler::print_timers() {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // do nothing
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }