Mercurial > hg > graal-compiler
annotate src/share/vm/opto/compile.cpp @ 244:524eca34ea76
6684714: Optimize EA Connection Graph build performance
Summary: switch on EA by default, optimize Connection Graph construction
Reviewed-by: rasbold, never
author | kvn |
---|---|
date | Thu, 03 Jul 2008 18:02:47 -0700 |
parents | 1dd146f17531 |
children | 4a4c365f777d |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright 1997-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_compile.cpp.incl" | |
27 | |
28 /// Support for intrinsics. | |
29 | |
30 // Return the index at which m must be inserted (or already exists). | |
31 // The sort order is by the address of the ciMethod, with is_virtual as minor key. | |
32 int Compile::intrinsic_insertion_index(ciMethod* m, bool is_virtual) { | |
33 #ifdef ASSERT | |
34 for (int i = 1; i < _intrinsics->length(); i++) { | |
35 CallGenerator* cg1 = _intrinsics->at(i-1); | |
36 CallGenerator* cg2 = _intrinsics->at(i); | |
37 assert(cg1->method() != cg2->method() | |
38 ? cg1->method() < cg2->method() | |
39 : cg1->is_virtual() < cg2->is_virtual(), | |
40 "compiler intrinsics list must stay sorted"); | |
41 } | |
42 #endif | |
43 // Binary search sorted list, in decreasing intervals [lo, hi]. | |
44 int lo = 0, hi = _intrinsics->length()-1; | |
45 while (lo <= hi) { | |
46 int mid = (uint)(hi + lo) / 2; | |
47 ciMethod* mid_m = _intrinsics->at(mid)->method(); | |
48 if (m < mid_m) { | |
49 hi = mid-1; | |
50 } else if (m > mid_m) { | |
51 lo = mid+1; | |
52 } else { | |
53 // look at minor sort key | |
54 bool mid_virt = _intrinsics->at(mid)->is_virtual(); | |
55 if (is_virtual < mid_virt) { | |
56 hi = mid-1; | |
57 } else if (is_virtual > mid_virt) { | |
58 lo = mid+1; | |
59 } else { | |
60 return mid; // exact match | |
61 } | |
62 } | |
63 } | |
64 return lo; // inexact match | |
65 } | |
66 | |
67 void Compile::register_intrinsic(CallGenerator* cg) { | |
68 if (_intrinsics == NULL) { | |
69 _intrinsics = new GrowableArray<CallGenerator*>(60); | |
70 } | |
71 // This code is stolen from ciObjectFactory::insert. | |
72 // Really, GrowableArray should have methods for | |
73 // insert_at, remove_at, and binary_search. | |
74 int len = _intrinsics->length(); | |
75 int index = intrinsic_insertion_index(cg->method(), cg->is_virtual()); | |
76 if (index == len) { | |
77 _intrinsics->append(cg); | |
78 } else { | |
79 #ifdef ASSERT | |
80 CallGenerator* oldcg = _intrinsics->at(index); | |
81 assert(oldcg->method() != cg->method() || oldcg->is_virtual() != cg->is_virtual(), "don't register twice"); | |
82 #endif | |
83 _intrinsics->append(_intrinsics->at(len-1)); | |
84 int pos; | |
85 for (pos = len-2; pos >= index; pos--) { | |
86 _intrinsics->at_put(pos+1,_intrinsics->at(pos)); | |
87 } | |
88 _intrinsics->at_put(index, cg); | |
89 } | |
90 assert(find_intrinsic(cg->method(), cg->is_virtual()) == cg, "registration worked"); | |
91 } | |
92 | |
93 CallGenerator* Compile::find_intrinsic(ciMethod* m, bool is_virtual) { | |
94 assert(m->is_loaded(), "don't try this on unloaded methods"); | |
95 if (_intrinsics != NULL) { | |
96 int index = intrinsic_insertion_index(m, is_virtual); | |
97 if (index < _intrinsics->length() | |
98 && _intrinsics->at(index)->method() == m | |
99 && _intrinsics->at(index)->is_virtual() == is_virtual) { | |
100 return _intrinsics->at(index); | |
101 } | |
102 } | |
103 // Lazily create intrinsics for intrinsic IDs well-known in the runtime. | |
104 if (m->intrinsic_id() != vmIntrinsics::_none) { | |
105 CallGenerator* cg = make_vm_intrinsic(m, is_virtual); | |
106 if (cg != NULL) { | |
107 // Save it for next time: | |
108 register_intrinsic(cg); | |
109 return cg; | |
110 } else { | |
111 gather_intrinsic_statistics(m->intrinsic_id(), is_virtual, _intrinsic_disabled); | |
112 } | |
113 } | |
114 return NULL; | |
115 } | |
116 | |
117 // Compile:: register_library_intrinsics and make_vm_intrinsic are defined | |
118 // in library_call.cpp. | |
119 | |
120 | |
121 #ifndef PRODUCT | |
122 // statistics gathering... | |
123 | |
124 juint Compile::_intrinsic_hist_count[vmIntrinsics::ID_LIMIT] = {0}; | |
125 jubyte Compile::_intrinsic_hist_flags[vmIntrinsics::ID_LIMIT] = {0}; | |
126 | |
127 bool Compile::gather_intrinsic_statistics(vmIntrinsics::ID id, bool is_virtual, int flags) { | |
128 assert(id > vmIntrinsics::_none && id < vmIntrinsics::ID_LIMIT, "oob"); | |
129 int oflags = _intrinsic_hist_flags[id]; | |
130 assert(flags != 0, "what happened?"); | |
131 if (is_virtual) { | |
132 flags |= _intrinsic_virtual; | |
133 } | |
134 bool changed = (flags != oflags); | |
135 if ((flags & _intrinsic_worked) != 0) { | |
136 juint count = (_intrinsic_hist_count[id] += 1); | |
137 if (count == 1) { | |
138 changed = true; // first time | |
139 } | |
140 // increment the overall count also: | |
141 _intrinsic_hist_count[vmIntrinsics::_none] += 1; | |
142 } | |
143 if (changed) { | |
144 if (((oflags ^ flags) & _intrinsic_virtual) != 0) { | |
145 // Something changed about the intrinsic's virtuality. | |
146 if ((flags & _intrinsic_virtual) != 0) { | |
147 // This is the first use of this intrinsic as a virtual call. | |
148 if (oflags != 0) { | |
149 // We already saw it as a non-virtual, so note both cases. | |
150 flags |= _intrinsic_both; | |
151 } | |
152 } else if ((oflags & _intrinsic_both) == 0) { | |
153 // This is the first use of this intrinsic as a non-virtual | |
154 flags |= _intrinsic_both; | |
155 } | |
156 } | |
157 _intrinsic_hist_flags[id] = (jubyte) (oflags | flags); | |
158 } | |
159 // update the overall flags also: | |
160 _intrinsic_hist_flags[vmIntrinsics::_none] |= (jubyte) flags; | |
161 return changed; | |
162 } | |
163 | |
164 static char* format_flags(int flags, char* buf) { | |
165 buf[0] = 0; | |
166 if ((flags & Compile::_intrinsic_worked) != 0) strcat(buf, ",worked"); | |
167 if ((flags & Compile::_intrinsic_failed) != 0) strcat(buf, ",failed"); | |
168 if ((flags & Compile::_intrinsic_disabled) != 0) strcat(buf, ",disabled"); | |
169 if ((flags & Compile::_intrinsic_virtual) != 0) strcat(buf, ",virtual"); | |
170 if ((flags & Compile::_intrinsic_both) != 0) strcat(buf, ",nonvirtual"); | |
171 if (buf[0] == 0) strcat(buf, ","); | |
172 assert(buf[0] == ',', "must be"); | |
173 return &buf[1]; | |
174 } | |
175 | |
176 void Compile::print_intrinsic_statistics() { | |
177 char flagsbuf[100]; | |
178 ttyLocker ttyl; | |
179 if (xtty != NULL) xtty->head("statistics type='intrinsic'"); | |
180 tty->print_cr("Compiler intrinsic usage:"); | |
181 juint total = _intrinsic_hist_count[vmIntrinsics::_none]; | |
182 if (total == 0) total = 1; // avoid div0 in case of no successes | |
183 #define PRINT_STAT_LINE(name, c, f) \ | |
184 tty->print_cr(" %4d (%4.1f%%) %s (%s)", (int)(c), ((c) * 100.0) / total, name, f); | |
185 for (int index = 1 + (int)vmIntrinsics::_none; index < (int)vmIntrinsics::ID_LIMIT; index++) { | |
186 vmIntrinsics::ID id = (vmIntrinsics::ID) index; | |
187 int flags = _intrinsic_hist_flags[id]; | |
188 juint count = _intrinsic_hist_count[id]; | |
189 if ((flags | count) != 0) { | |
190 PRINT_STAT_LINE(vmIntrinsics::name_at(id), count, format_flags(flags, flagsbuf)); | |
191 } | |
192 } | |
193 PRINT_STAT_LINE("total", total, format_flags(_intrinsic_hist_flags[vmIntrinsics::_none], flagsbuf)); | |
194 if (xtty != NULL) xtty->tail("statistics"); | |
195 } | |
196 | |
197 void Compile::print_statistics() { | |
198 { ttyLocker ttyl; | |
199 if (xtty != NULL) xtty->head("statistics type='opto'"); | |
200 Parse::print_statistics(); | |
201 PhaseCCP::print_statistics(); | |
202 PhaseRegAlloc::print_statistics(); | |
203 Scheduling::print_statistics(); | |
204 PhasePeephole::print_statistics(); | |
205 PhaseIdealLoop::print_statistics(); | |
206 if (xtty != NULL) xtty->tail("statistics"); | |
207 } | |
208 if (_intrinsic_hist_flags[vmIntrinsics::_none] != 0) { | |
209 // put this under its own <statistics> element. | |
210 print_intrinsic_statistics(); | |
211 } | |
212 } | |
213 #endif //PRODUCT | |
214 | |
215 // Support for bundling info | |
216 Bundle* Compile::node_bundling(const Node *n) { | |
217 assert(valid_bundle_info(n), "oob"); | |
218 return &_node_bundling_base[n->_idx]; | |
219 } | |
220 | |
221 bool Compile::valid_bundle_info(const Node *n) { | |
222 return (_node_bundling_limit > n->_idx); | |
223 } | |
224 | |
225 | |
226 // Identify all nodes that are reachable from below, useful. | |
227 // Use breadth-first pass that records state in a Unique_Node_List, | |
228 // recursive traversal is slower. | |
229 void Compile::identify_useful_nodes(Unique_Node_List &useful) { | |
230 int estimated_worklist_size = unique(); | |
231 useful.map( estimated_worklist_size, NULL ); // preallocate space | |
232 | |
233 // Initialize worklist | |
234 if (root() != NULL) { useful.push(root()); } | |
235 // If 'top' is cached, declare it useful to preserve cached node | |
236 if( cached_top_node() ) { useful.push(cached_top_node()); } | |
237 | |
238 // Push all useful nodes onto the list, breadthfirst | |
239 for( uint next = 0; next < useful.size(); ++next ) { | |
240 assert( next < unique(), "Unique useful nodes < total nodes"); | |
241 Node *n = useful.at(next); | |
242 uint max = n->len(); | |
243 for( uint i = 0; i < max; ++i ) { | |
244 Node *m = n->in(i); | |
245 if( m == NULL ) continue; | |
246 useful.push(m); | |
247 } | |
248 } | |
249 } | |
250 | |
251 // Disconnect all useless nodes by disconnecting those at the boundary. | |
252 void Compile::remove_useless_nodes(Unique_Node_List &useful) { | |
253 uint next = 0; | |
254 while( next < useful.size() ) { | |
255 Node *n = useful.at(next++); | |
256 // Use raw traversal of out edges since this code removes out edges | |
257 int max = n->outcnt(); | |
258 for (int j = 0; j < max; ++j ) { | |
259 Node* child = n->raw_out(j); | |
260 if( ! useful.member(child) ) { | |
261 assert( !child->is_top() || child != top(), | |
262 "If top is cached in Compile object it is in useful list"); | |
263 // Only need to remove this out-edge to the useless node | |
264 n->raw_del_out(j); | |
265 --j; | |
266 --max; | |
267 } | |
268 } | |
269 if (n->outcnt() == 1 && n->has_special_unique_user()) { | |
270 record_for_igvn( n->unique_out() ); | |
271 } | |
272 } | |
273 debug_only(verify_graph_edges(true/*check for no_dead_code*/);) | |
274 } | |
275 | |
276 //------------------------------frame_size_in_words----------------------------- | |
277 // frame_slots in units of words | |
278 int Compile::frame_size_in_words() const { | |
279 // shift is 0 in LP32 and 1 in LP64 | |
280 const int shift = (LogBytesPerWord - LogBytesPerInt); | |
281 int words = _frame_slots >> shift; | |
282 assert( words << shift == _frame_slots, "frame size must be properly aligned in LP64" ); | |
283 return words; | |
284 } | |
285 | |
286 // ============================================================================ | |
287 //------------------------------CompileWrapper--------------------------------- | |
288 class CompileWrapper : public StackObj { | |
289 Compile *const _compile; | |
290 public: | |
291 CompileWrapper(Compile* compile); | |
292 | |
293 ~CompileWrapper(); | |
294 }; | |
295 | |
296 CompileWrapper::CompileWrapper(Compile* compile) : _compile(compile) { | |
297 // the Compile* pointer is stored in the current ciEnv: | |
298 ciEnv* env = compile->env(); | |
299 assert(env == ciEnv::current(), "must already be a ciEnv active"); | |
300 assert(env->compiler_data() == NULL, "compile already active?"); | |
301 env->set_compiler_data(compile); | |
302 assert(compile == Compile::current(), "sanity"); | |
303 | |
304 compile->set_type_dict(NULL); | |
305 compile->set_type_hwm(NULL); | |
306 compile->set_type_last_size(0); | |
307 compile->set_last_tf(NULL, NULL); | |
308 compile->set_indexSet_arena(NULL); | |
309 compile->set_indexSet_free_block_list(NULL); | |
310 compile->init_type_arena(); | |
311 Type::Initialize(compile); | |
312 _compile->set_scratch_buffer_blob(NULL); | |
313 _compile->begin_method(); | |
314 } | |
315 CompileWrapper::~CompileWrapper() { | |
316 _compile->end_method(); | |
317 if (_compile->scratch_buffer_blob() != NULL) | |
318 BufferBlob::free(_compile->scratch_buffer_blob()); | |
319 _compile->env()->set_compiler_data(NULL); | |
320 } | |
321 | |
322 | |
323 //----------------------------print_compile_messages--------------------------- | |
324 void Compile::print_compile_messages() { | |
325 #ifndef PRODUCT | |
326 // Check if recompiling | |
327 if (_subsume_loads == false && PrintOpto) { | |
328 // Recompiling without allowing machine instructions to subsume loads | |
329 tty->print_cr("*********************************************************"); | |
330 tty->print_cr("** Bailout: Recompile without subsuming loads **"); | |
331 tty->print_cr("*********************************************************"); | |
332 } | |
38
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
333 if (_do_escape_analysis != DoEscapeAnalysis && PrintOpto) { |
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
334 // Recompiling without escape analysis |
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
335 tty->print_cr("*********************************************************"); |
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
336 tty->print_cr("** Bailout: Recompile without escape analysis **"); |
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
337 tty->print_cr("*********************************************************"); |
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
338 } |
0 | 339 if (env()->break_at_compile()) { |
340 // Open the debugger when compiing this method. | |
341 tty->print("### Breaking when compiling: "); | |
342 method()->print_short_name(); | |
343 tty->cr(); | |
344 BREAKPOINT; | |
345 } | |
346 | |
347 if( PrintOpto ) { | |
348 if (is_osr_compilation()) { | |
349 tty->print("[OSR]%3d", _compile_id); | |
350 } else { | |
351 tty->print("%3d", _compile_id); | |
352 } | |
353 } | |
354 #endif | |
355 } | |
356 | |
357 | |
358 void Compile::init_scratch_buffer_blob() { | |
359 if( scratch_buffer_blob() != NULL ) return; | |
360 | |
361 // Construct a temporary CodeBuffer to have it construct a BufferBlob | |
362 // Cache this BufferBlob for this compile. | |
363 ResourceMark rm; | |
364 int size = (MAX_inst_size + MAX_stubs_size + MAX_const_size); | |
365 BufferBlob* blob = BufferBlob::create("Compile::scratch_buffer", size); | |
366 // Record the buffer blob for next time. | |
367 set_scratch_buffer_blob(blob); | |
163 | 368 // Have we run out of code space? |
369 if (scratch_buffer_blob() == NULL) { | |
370 // Let CompilerBroker disable further compilations. | |
371 record_failure("Not enough space for scratch buffer in CodeCache"); | |
372 return; | |
373 } | |
0 | 374 |
375 // Initialize the relocation buffers | |
376 relocInfo* locs_buf = (relocInfo*) blob->instructions_end() - MAX_locs_size; | |
377 set_scratch_locs_memory(locs_buf); | |
378 } | |
379 | |
380 | |
381 //-----------------------scratch_emit_size------------------------------------- | |
382 // Helper function that computes size by emitting code | |
383 uint Compile::scratch_emit_size(const Node* n) { | |
384 // Emit into a trash buffer and count bytes emitted. | |
385 // This is a pretty expensive way to compute a size, | |
386 // but it works well enough if seldom used. | |
387 // All common fixed-size instructions are given a size | |
388 // method by the AD file. | |
389 // Note that the scratch buffer blob and locs memory are | |
390 // allocated at the beginning of the compile task, and | |
391 // may be shared by several calls to scratch_emit_size. | |
392 // The allocation of the scratch buffer blob is particularly | |
393 // expensive, since it has to grab the code cache lock. | |
394 BufferBlob* blob = this->scratch_buffer_blob(); | |
395 assert(blob != NULL, "Initialize BufferBlob at start"); | |
396 assert(blob->size() > MAX_inst_size, "sanity"); | |
397 relocInfo* locs_buf = scratch_locs_memory(); | |
398 address blob_begin = blob->instructions_begin(); | |
399 address blob_end = (address)locs_buf; | |
400 assert(blob->instructions_contains(blob_end), "sanity"); | |
401 CodeBuffer buf(blob_begin, blob_end - blob_begin); | |
402 buf.initialize_consts_size(MAX_const_size); | |
403 buf.initialize_stubs_size(MAX_stubs_size); | |
404 assert(locs_buf != NULL, "sanity"); | |
405 int lsize = MAX_locs_size / 2; | |
406 buf.insts()->initialize_shared_locs(&locs_buf[0], lsize); | |
407 buf.stubs()->initialize_shared_locs(&locs_buf[lsize], lsize); | |
408 n->emit(buf, this->regalloc()); | |
409 return buf.code_size(); | |
410 } | |
411 | |
412 | |
413 // ============================================================================ | |
414 //------------------------------Compile standard------------------------------- | |
415 debug_only( int Compile::_debug_idx = 100000; ) | |
416 | |
417 // Compile a method. entry_bci is -1 for normal compilations and indicates | |
418 // the continuation bci for on stack replacement. | |
419 | |
420 | |
38
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
421 Compile::Compile( ciEnv* ci_env, C2Compiler* compiler, ciMethod* target, int osr_bci, bool subsume_loads, bool do_escape_analysis ) |
0 | 422 : Phase(Compiler), |
423 _env(ci_env), | |
424 _log(ci_env->log()), | |
425 _compile_id(ci_env->compile_id()), | |
426 _save_argument_registers(false), | |
427 _stub_name(NULL), | |
428 _stub_function(NULL), | |
429 _stub_entry_point(NULL), | |
430 _method(target), | |
431 _entry_bci(osr_bci), | |
432 _initial_gvn(NULL), | |
433 _for_igvn(NULL), | |
434 _warm_calls(NULL), | |
435 _subsume_loads(subsume_loads), | |
38
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
436 _do_escape_analysis(do_escape_analysis), |
0 | 437 _failure_reason(NULL), |
438 _code_buffer("Compile::Fill_buffer"), | |
439 _orig_pc_slot(0), | |
440 _orig_pc_slot_offset_in_bytes(0), | |
441 _node_bundling_limit(0), | |
442 _node_bundling_base(NULL), | |
443 #ifndef PRODUCT | |
444 _trace_opto_output(TraceOptoOutput || method()->has_option("TraceOptoOutput")), | |
445 _printer(IdealGraphPrinter::printer()), | |
446 #endif | |
447 _congraph(NULL) { | |
448 C = this; | |
449 | |
450 CompileWrapper cw(this); | |
451 #ifndef PRODUCT | |
452 if (TimeCompiler2) { | |
453 tty->print(" "); | |
454 target->holder()->name()->print(); | |
455 tty->print("."); | |
456 target->print_short_name(); | |
457 tty->print(" "); | |
458 } | |
459 TraceTime t1("Total compilation time", &_t_totalCompilation, TimeCompiler, TimeCompiler2); | |
460 TraceTime t2(NULL, &_t_methodCompilation, TimeCompiler, false); | |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
65
diff
changeset
|
461 bool print_opto_assembly = PrintOptoAssembly || _method->has_option("PrintOptoAssembly"); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
65
diff
changeset
|
462 if (!print_opto_assembly) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
65
diff
changeset
|
463 bool print_assembly = (PrintAssembly || _method->should_print_assembly()); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
65
diff
changeset
|
464 if (print_assembly && !Disassembler::can_decode()) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
65
diff
changeset
|
465 tty->print_cr("PrintAssembly request changed to PrintOptoAssembly"); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
65
diff
changeset
|
466 print_opto_assembly = true; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
65
diff
changeset
|
467 } |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
65
diff
changeset
|
468 } |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
65
diff
changeset
|
469 set_print_assembly(print_opto_assembly); |
0 | 470 #endif |
471 | |
472 if (ProfileTraps) { | |
473 // Make sure the method being compiled gets its own MDO, | |
474 // so we can at least track the decompile_count(). | |
475 method()->build_method_data(); | |
476 } | |
477 | |
478 Init(::AliasLevel); | |
479 | |
480 | |
481 print_compile_messages(); | |
482 | |
483 if (UseOldInlining || PrintCompilation NOT_PRODUCT( || PrintOpto) ) | |
484 _ilt = InlineTree::build_inline_tree_root(); | |
485 else | |
486 _ilt = NULL; | |
487 | |
488 // Even if NO memory addresses are used, MergeMem nodes must have at least 1 slice | |
489 assert(num_alias_types() >= AliasIdxRaw, ""); | |
490 | |
491 #define MINIMUM_NODE_HASH 1023 | |
492 // Node list that Iterative GVN will start with | |
493 Unique_Node_List for_igvn(comp_arena()); | |
494 set_for_igvn(&for_igvn); | |
495 | |
496 // GVN that will be run immediately on new nodes | |
497 uint estimated_size = method()->code_size()*4+64; | |
498 estimated_size = (estimated_size < MINIMUM_NODE_HASH ? MINIMUM_NODE_HASH : estimated_size); | |
499 PhaseGVN gvn(node_arena(), estimated_size); | |
500 set_initial_gvn(&gvn); | |
501 | |
502 { // Scope for timing the parser | |
503 TracePhase t3("parse", &_t_parser, true); | |
504 | |
505 // Put top into the hash table ASAP. | |
506 initial_gvn()->transform_no_reclaim(top()); | |
507 | |
508 // Set up tf(), start(), and find a CallGenerator. | |
509 CallGenerator* cg; | |
510 if (is_osr_compilation()) { | |
511 const TypeTuple *domain = StartOSRNode::osr_domain(); | |
512 const TypeTuple *range = TypeTuple::make_range(method()->signature()); | |
513 init_tf(TypeFunc::make(domain, range)); | |
514 StartNode* s = new (this, 2) StartOSRNode(root(), domain); | |
515 initial_gvn()->set_type_bottom(s); | |
516 init_start(s); | |
517 cg = CallGenerator::for_osr(method(), entry_bci()); | |
518 } else { | |
519 // Normal case. | |
520 init_tf(TypeFunc::make(method())); | |
521 StartNode* s = new (this, 2) StartNode(root(), tf()->domain()); | |
522 initial_gvn()->set_type_bottom(s); | |
523 init_start(s); | |
524 float past_uses = method()->interpreter_invocation_count(); | |
525 float expected_uses = past_uses; | |
526 cg = CallGenerator::for_inline(method(), expected_uses); | |
527 } | |
528 if (failing()) return; | |
529 if (cg == NULL) { | |
530 record_method_not_compilable_all_tiers("cannot parse method"); | |
531 return; | |
532 } | |
533 JVMState* jvms = build_start_state(start(), tf()); | |
534 if ((jvms = cg->generate(jvms)) == NULL) { | |
535 record_method_not_compilable("method parse failed"); | |
536 return; | |
537 } | |
538 GraphKit kit(jvms); | |
539 | |
540 if (!kit.stopped()) { | |
541 // Accept return values, and transfer control we know not where. | |
542 // This is done by a special, unique ReturnNode bound to root. | |
543 return_values(kit.jvms()); | |
544 } | |
545 | |
546 if (kit.has_exceptions()) { | |
547 // Any exceptions that escape from this call must be rethrown | |
548 // to whatever caller is dynamically above us on the stack. | |
549 // This is done by a special, unique RethrowNode bound to root. | |
550 rethrow_exceptions(kit.transfer_exceptions_into_jvms()); | |
551 } | |
552 | |
553 // Remove clutter produced by parsing. | |
554 if (!failing()) { | |
555 ResourceMark rm; | |
556 PhaseRemoveUseless pru(initial_gvn(), &for_igvn); | |
557 } | |
558 } | |
559 | |
560 // Note: Large methods are capped off in do_one_bytecode(). | |
561 if (failing()) return; | |
562 | |
563 // After parsing, node notes are no longer automagic. | |
564 // They must be propagated by register_new_node_with_optimizer(), | |
565 // clone(), or the like. | |
566 set_default_node_notes(NULL); | |
567 | |
568 for (;;) { | |
569 int successes = Inline_Warm(); | |
570 if (failing()) return; | |
571 if (successes == 0) break; | |
572 } | |
573 | |
574 // Drain the list. | |
575 Finish_Warm(); | |
576 #ifndef PRODUCT | |
577 if (_printer) { | |
578 _printer->print_inlining(this); | |
579 } | |
580 #endif | |
581 | |
582 if (failing()) return; | |
583 NOT_PRODUCT( verify_graph_edges(); ) | |
584 | |
585 // Perform escape analysis | |
244
524eca34ea76
6684714: Optimize EA Connection Graph build performance
kvn
parents:
223
diff
changeset
|
586 if (_do_escape_analysis && ConnectionGraph::has_candidates(this)) { |
524eca34ea76
6684714: Optimize EA Connection Graph build performance
kvn
parents:
223
diff
changeset
|
587 TracePhase t2("escapeAnalysis", &_t_escapeAnalysis, true); |
524eca34ea76
6684714: Optimize EA Connection Graph build performance
kvn
parents:
223
diff
changeset
|
588 |
524eca34ea76
6684714: Optimize EA Connection Graph build performance
kvn
parents:
223
diff
changeset
|
589 _congraph = new(comp_arena()) ConnectionGraph(this); |
524eca34ea76
6684714: Optimize EA Connection Graph build performance
kvn
parents:
223
diff
changeset
|
590 bool has_non_escaping_obj = _congraph->compute_escape(); |
38
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
591 |
0 | 592 #ifndef PRODUCT |
593 if (PrintEscapeAnalysis) { | |
594 _congraph->dump(); | |
595 } | |
596 #endif | |
244
524eca34ea76
6684714: Optimize EA Connection Graph build performance
kvn
parents:
223
diff
changeset
|
597 if (!has_non_escaping_obj) { |
524eca34ea76
6684714: Optimize EA Connection Graph build performance
kvn
parents:
223
diff
changeset
|
598 _congraph = NULL; |
524eca34ea76
6684714: Optimize EA Connection Graph build performance
kvn
parents:
223
diff
changeset
|
599 } |
524eca34ea76
6684714: Optimize EA Connection Graph build performance
kvn
parents:
223
diff
changeset
|
600 |
524eca34ea76
6684714: Optimize EA Connection Graph build performance
kvn
parents:
223
diff
changeset
|
601 if (failing()) return; |
0 | 602 } |
603 // Now optimize | |
604 Optimize(); | |
605 if (failing()) return; | |
606 NOT_PRODUCT( verify_graph_edges(); ) | |
607 | |
222 | 608 print_method("Before Matching"); |
609 | |
0 | 610 #ifndef PRODUCT |
611 if (PrintIdeal) { | |
612 ttyLocker ttyl; // keep the following output all in one block | |
613 // This output goes directly to the tty, not the compiler log. | |
614 // To enable tools to match it up with the compilation activity, | |
615 // be sure to tag this tty output with the compile ID. | |
616 if (xtty != NULL) { | |
617 xtty->head("ideal compile_id='%d'%s", compile_id(), | |
618 is_osr_compilation() ? " compile_kind='osr'" : | |
619 ""); | |
620 } | |
621 root()->dump(9999); | |
622 if (xtty != NULL) { | |
623 xtty->tail("ideal"); | |
624 } | |
625 } | |
626 #endif | |
627 | |
628 // Now that we know the size of all the monitors we can add a fixed slot | |
629 // for the original deopt pc. | |
630 | |
631 _orig_pc_slot = fixed_slots(); | |
632 int next_slot = _orig_pc_slot + (sizeof(address) / VMRegImpl::stack_slot_size); | |
633 set_fixed_slots(next_slot); | |
634 | |
635 // Now generate code | |
636 Code_Gen(); | |
637 if (failing()) return; | |
638 | |
639 // Check if we want to skip execution of all compiled code. | |
640 { | |
641 #ifndef PRODUCT | |
642 if (OptoNoExecute) { | |
643 record_method_not_compilable("+OptoNoExecute"); // Flag as failed | |
644 return; | |
645 } | |
646 TracePhase t2("install_code", &_t_registerMethod, TimeCompiler); | |
647 #endif | |
648 | |
649 if (is_osr_compilation()) { | |
650 _code_offsets.set_value(CodeOffsets::Verified_Entry, 0); | |
651 _code_offsets.set_value(CodeOffsets::OSR_Entry, _first_block_size); | |
652 } else { | |
653 _code_offsets.set_value(CodeOffsets::Verified_Entry, _first_block_size); | |
654 _code_offsets.set_value(CodeOffsets::OSR_Entry, 0); | |
655 } | |
656 | |
657 env()->register_method(_method, _entry_bci, | |
658 &_code_offsets, | |
659 _orig_pc_slot_offset_in_bytes, | |
660 code_buffer(), | |
661 frame_size_in_words(), _oop_map_set, | |
662 &_handler_table, &_inc_table, | |
663 compiler, | |
664 env()->comp_level(), | |
665 true, /*has_debug_info*/ | |
666 has_unsafe_access() | |
667 ); | |
668 } | |
669 } | |
670 | |
671 //------------------------------Compile---------------------------------------- | |
672 // Compile a runtime stub | |
673 Compile::Compile( ciEnv* ci_env, | |
674 TypeFunc_generator generator, | |
675 address stub_function, | |
676 const char *stub_name, | |
677 int is_fancy_jump, | |
678 bool pass_tls, | |
679 bool save_arg_registers, | |
680 bool return_pc ) | |
681 : Phase(Compiler), | |
682 _env(ci_env), | |
683 _log(ci_env->log()), | |
684 _compile_id(-1), | |
685 _save_argument_registers(save_arg_registers), | |
686 _method(NULL), | |
687 _stub_name(stub_name), | |
688 _stub_function(stub_function), | |
689 _stub_entry_point(NULL), | |
690 _entry_bci(InvocationEntryBci), | |
691 _initial_gvn(NULL), | |
692 _for_igvn(NULL), | |
693 _warm_calls(NULL), | |
694 _orig_pc_slot(0), | |
695 _orig_pc_slot_offset_in_bytes(0), | |
696 _subsume_loads(true), | |
38
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
697 _do_escape_analysis(false), |
0 | 698 _failure_reason(NULL), |
699 _code_buffer("Compile::Fill_buffer"), | |
700 _node_bundling_limit(0), | |
701 _node_bundling_base(NULL), | |
702 #ifndef PRODUCT | |
703 _trace_opto_output(TraceOptoOutput), | |
704 _printer(NULL), | |
705 #endif | |
706 _congraph(NULL) { | |
707 C = this; | |
708 | |
709 #ifndef PRODUCT | |
710 TraceTime t1(NULL, &_t_totalCompilation, TimeCompiler, false); | |
711 TraceTime t2(NULL, &_t_stubCompilation, TimeCompiler, false); | |
712 set_print_assembly(PrintFrameConverterAssembly); | |
713 #endif | |
714 CompileWrapper cw(this); | |
715 Init(/*AliasLevel=*/ 0); | |
716 init_tf((*generator)()); | |
717 | |
718 { | |
719 // The following is a dummy for the sake of GraphKit::gen_stub | |
720 Unique_Node_List for_igvn(comp_arena()); | |
721 set_for_igvn(&for_igvn); // not used, but some GraphKit guys push on this | |
722 PhaseGVN gvn(Thread::current()->resource_area(),255); | |
723 set_initial_gvn(&gvn); // not significant, but GraphKit guys use it pervasively | |
724 gvn.transform_no_reclaim(top()); | |
725 | |
726 GraphKit kit; | |
727 kit.gen_stub(stub_function, stub_name, is_fancy_jump, pass_tls, return_pc); | |
728 } | |
729 | |
730 NOT_PRODUCT( verify_graph_edges(); ) | |
731 Code_Gen(); | |
732 if (failing()) return; | |
733 | |
734 | |
735 // Entry point will be accessed using compile->stub_entry_point(); | |
736 if (code_buffer() == NULL) { | |
737 Matcher::soft_match_failure(); | |
738 } else { | |
739 if (PrintAssembly && (WizardMode || Verbose)) | |
740 tty->print_cr("### Stub::%s", stub_name); | |
741 | |
742 if (!failing()) { | |
743 assert(_fixed_slots == 0, "no fixed slots used for runtime stubs"); | |
744 | |
745 // Make the NMethod | |
746 // For now we mark the frame as never safe for profile stackwalking | |
747 RuntimeStub *rs = RuntimeStub::new_runtime_stub(stub_name, | |
748 code_buffer(), | |
749 CodeOffsets::frame_never_safe, | |
750 // _code_offsets.value(CodeOffsets::Frame_Complete), | |
751 frame_size_in_words(), | |
752 _oop_map_set, | |
753 save_arg_registers); | |
754 assert(rs != NULL && rs->is_runtime_stub(), "sanity check"); | |
755 | |
756 _stub_entry_point = rs->entry_point(); | |
757 } | |
758 } | |
759 } | |
760 | |
761 #ifndef PRODUCT | |
762 void print_opto_verbose_signature( const TypeFunc *j_sig, const char *stub_name ) { | |
763 if(PrintOpto && Verbose) { | |
764 tty->print("%s ", stub_name); j_sig->print_flattened(); tty->cr(); | |
765 } | |
766 } | |
767 #endif | |
768 | |
769 void Compile::print_codes() { | |
770 } | |
771 | |
772 //------------------------------Init------------------------------------------- | |
773 // Prepare for a single compilation | |
774 void Compile::Init(int aliaslevel) { | |
775 _unique = 0; | |
776 _regalloc = NULL; | |
777 | |
778 _tf = NULL; // filled in later | |
779 _top = NULL; // cached later | |
780 _matcher = NULL; // filled in later | |
781 _cfg = NULL; // filled in later | |
782 | |
783 set_24_bit_selection_and_mode(Use24BitFP, false); | |
784 | |
785 _node_note_array = NULL; | |
786 _default_node_notes = NULL; | |
787 | |
788 _immutable_memory = NULL; // filled in at first inquiry | |
789 | |
790 // Globally visible Nodes | |
791 // First set TOP to NULL to give safe behavior during creation of RootNode | |
792 set_cached_top_node(NULL); | |
793 set_root(new (this, 3) RootNode()); | |
794 // Now that you have a Root to point to, create the real TOP | |
795 set_cached_top_node( new (this, 1) ConNode(Type::TOP) ); | |
796 set_recent_alloc(NULL, NULL); | |
797 | |
798 // Create Debug Information Recorder to record scopes, oopmaps, etc. | |
799 env()->set_oop_recorder(new OopRecorder(comp_arena())); | |
800 env()->set_debug_info(new DebugInformationRecorder(env()->oop_recorder())); | |
801 env()->set_dependencies(new Dependencies(env())); | |
802 | |
803 _fixed_slots = 0; | |
804 set_has_split_ifs(false); | |
805 set_has_loops(has_method() && method()->has_loops()); // first approximation | |
806 _deopt_happens = true; // start out assuming the worst | |
807 _trap_can_recompile = false; // no traps emitted yet | |
808 _major_progress = true; // start out assuming good things will happen | |
809 set_has_unsafe_access(false); | |
810 Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist)); | |
811 set_decompile_count(0); | |
812 | |
813 // Compilation level related initialization | |
814 if (env()->comp_level() == CompLevel_fast_compile) { | |
815 set_num_loop_opts(Tier1LoopOptsCount); | |
816 set_do_inlining(Tier1Inline != 0); | |
817 set_max_inline_size(Tier1MaxInlineSize); | |
818 set_freq_inline_size(Tier1FreqInlineSize); | |
819 set_do_scheduling(false); | |
820 set_do_count_invocations(Tier1CountInvocations); | |
821 set_do_method_data_update(Tier1UpdateMethodData); | |
822 } else { | |
823 assert(env()->comp_level() == CompLevel_full_optimization, "unknown comp level"); | |
824 set_num_loop_opts(LoopOptsCount); | |
825 set_do_inlining(Inline); | |
826 set_max_inline_size(MaxInlineSize); | |
827 set_freq_inline_size(FreqInlineSize); | |
828 set_do_scheduling(OptoScheduling); | |
829 set_do_count_invocations(false); | |
830 set_do_method_data_update(false); | |
831 } | |
832 | |
833 if (debug_info()->recording_non_safepoints()) { | |
834 set_node_note_array(new(comp_arena()) GrowableArray<Node_Notes*> | |
835 (comp_arena(), 8, 0, NULL)); | |
836 set_default_node_notes(Node_Notes::make(this)); | |
837 } | |
838 | |
839 // // -- Initialize types before each compile -- | |
840 // // Update cached type information | |
841 // if( _method && _method->constants() ) | |
842 // Type::update_loaded_types(_method, _method->constants()); | |
843 | |
844 // Init alias_type map. | |
38
b789bcaf2dd9
6667610: (Escape Analysis) retry compilation without EA if it fails
kvn
parents:
0
diff
changeset
|
845 if (!_do_escape_analysis && aliaslevel == 3) |
0 | 846 aliaslevel = 2; // No unique types without escape analysis |
847 _AliasLevel = aliaslevel; | |
848 const int grow_ats = 16; | |
849 _max_alias_types = grow_ats; | |
850 _alias_types = NEW_ARENA_ARRAY(comp_arena(), AliasType*, grow_ats); | |
851 AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType, grow_ats); | |
852 Copy::zero_to_bytes(ats, sizeof(AliasType)*grow_ats); | |
853 { | |
854 for (int i = 0; i < grow_ats; i++) _alias_types[i] = &ats[i]; | |
855 } | |
856 // Initialize the first few types. | |
857 _alias_types[AliasIdxTop]->Init(AliasIdxTop, NULL); | |
858 _alias_types[AliasIdxBot]->Init(AliasIdxBot, TypePtr::BOTTOM); | |
859 _alias_types[AliasIdxRaw]->Init(AliasIdxRaw, TypeRawPtr::BOTTOM); | |
860 _num_alias_types = AliasIdxRaw+1; | |
861 // Zero out the alias type cache. | |
862 Copy::zero_to_bytes(_alias_cache, sizeof(_alias_cache)); | |
863 // A NULL adr_type hits in the cache right away. Preload the right answer. | |
864 probe_alias_cache(NULL)->_index = AliasIdxTop; | |
865 | |
866 _intrinsics = NULL; | |
867 _macro_nodes = new GrowableArray<Node*>(comp_arena(), 8, 0, NULL); | |
868 register_library_intrinsics(); | |
869 } | |
870 | |
871 //---------------------------init_start---------------------------------------- | |
872 // Install the StartNode on this compile object. | |
873 void Compile::init_start(StartNode* s) { | |
874 if (failing()) | |
875 return; // already failing | |
876 assert(s == start(), ""); | |
877 } | |
878 | |
879 StartNode* Compile::start() const { | |
880 assert(!failing(), ""); | |
881 for (DUIterator_Fast imax, i = root()->fast_outs(imax); i < imax; i++) { | |
882 Node* start = root()->fast_out(i); | |
883 if( start->is_Start() ) | |
884 return start->as_Start(); | |
885 } | |
886 ShouldNotReachHere(); | |
887 return NULL; | |
888 } | |
889 | |
890 //-------------------------------immutable_memory------------------------------------- | |
891 // Access immutable memory | |
892 Node* Compile::immutable_memory() { | |
893 if (_immutable_memory != NULL) { | |
894 return _immutable_memory; | |
895 } | |
896 StartNode* s = start(); | |
897 for (DUIterator_Fast imax, i = s->fast_outs(imax); true; i++) { | |
898 Node *p = s->fast_out(i); | |
899 if (p != s && p->as_Proj()->_con == TypeFunc::Memory) { | |
900 _immutable_memory = p; | |
901 return _immutable_memory; | |
902 } | |
903 } | |
904 ShouldNotReachHere(); | |
905 return NULL; | |
906 } | |
907 | |
908 //----------------------set_cached_top_node------------------------------------ | |
909 // Install the cached top node, and make sure Node::is_top works correctly. | |
910 void Compile::set_cached_top_node(Node* tn) { | |
911 if (tn != NULL) verify_top(tn); | |
912 Node* old_top = _top; | |
913 _top = tn; | |
914 // Calling Node::setup_is_top allows the nodes the chance to adjust | |
915 // their _out arrays. | |
916 if (_top != NULL) _top->setup_is_top(); | |
917 if (old_top != NULL) old_top->setup_is_top(); | |
918 assert(_top == NULL || top()->is_top(), ""); | |
919 } | |
920 | |
921 #ifndef PRODUCT | |
922 void Compile::verify_top(Node* tn) const { | |
923 if (tn != NULL) { | |
924 assert(tn->is_Con(), "top node must be a constant"); | |
925 assert(((ConNode*)tn)->type() == Type::TOP, "top node must have correct type"); | |
926 assert(tn->in(0) != NULL, "must have live top node"); | |
927 } | |
928 } | |
929 #endif | |
930 | |
931 | |
932 ///-------------------Managing Per-Node Debug & Profile Info------------------- | |
933 | |
934 void Compile::grow_node_notes(GrowableArray<Node_Notes*>* arr, int grow_by) { | |
935 guarantee(arr != NULL, ""); | |
936 int num_blocks = arr->length(); | |
937 if (grow_by < num_blocks) grow_by = num_blocks; | |
938 int num_notes = grow_by * _node_notes_block_size; | |
939 Node_Notes* notes = NEW_ARENA_ARRAY(node_arena(), Node_Notes, num_notes); | |
940 Copy::zero_to_bytes(notes, num_notes * sizeof(Node_Notes)); | |
941 while (num_notes > 0) { | |
942 arr->append(notes); | |
943 notes += _node_notes_block_size; | |
944 num_notes -= _node_notes_block_size; | |
945 } | |
946 assert(num_notes == 0, "exact multiple, please"); | |
947 } | |
948 | |
949 bool Compile::copy_node_notes_to(Node* dest, Node* source) { | |
950 if (source == NULL || dest == NULL) return false; | |
951 | |
952 if (dest->is_Con()) | |
953 return false; // Do not push debug info onto constants. | |
954 | |
955 #ifdef ASSERT | |
956 // Leave a bread crumb trail pointing to the original node: | |
957 if (dest != NULL && dest != source && dest->debug_orig() == NULL) { | |
958 dest->set_debug_orig(source); | |
959 } | |
960 #endif | |
961 | |
962 if (node_note_array() == NULL) | |
963 return false; // Not collecting any notes now. | |
964 | |
965 // This is a copy onto a pre-existing node, which may already have notes. | |
966 // If both nodes have notes, do not overwrite any pre-existing notes. | |
967 Node_Notes* source_notes = node_notes_at(source->_idx); | |
968 if (source_notes == NULL || source_notes->is_clear()) return false; | |
969 Node_Notes* dest_notes = node_notes_at(dest->_idx); | |
970 if (dest_notes == NULL || dest_notes->is_clear()) { | |
971 return set_node_notes_at(dest->_idx, source_notes); | |
972 } | |
973 | |
974 Node_Notes merged_notes = (*source_notes); | |
975 // The order of operations here ensures that dest notes will win... | |
976 merged_notes.update_from(dest_notes); | |
977 return set_node_notes_at(dest->_idx, &merged_notes); | |
978 } | |
979 | |
980 | |
981 //--------------------------allow_range_check_smearing------------------------- | |
982 // Gating condition for coalescing similar range checks. | |
983 // Sometimes we try 'speculatively' replacing a series of a range checks by a | |
984 // single covering check that is at least as strong as any of them. | |
985 // If the optimization succeeds, the simplified (strengthened) range check | |
986 // will always succeed. If it fails, we will deopt, and then give up | |
987 // on the optimization. | |
988 bool Compile::allow_range_check_smearing() const { | |
989 // If this method has already thrown a range-check, | |
990 // assume it was because we already tried range smearing | |
991 // and it failed. | |
992 uint already_trapped = trap_count(Deoptimization::Reason_range_check); | |
993 return !already_trapped; | |
994 } | |
995 | |
996 | |
997 //------------------------------flatten_alias_type----------------------------- | |
998 const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const { | |
999 int offset = tj->offset(); | |
1000 TypePtr::PTR ptr = tj->ptr(); | |
1001 | |
1002 // Process weird unsafe references. | |
1003 if (offset == Type::OffsetBot && (tj->isa_instptr() /*|| tj->isa_klassptr()*/)) { | |
1004 assert(InlineUnsafeOps, "indeterminate pointers come only from unsafe ops"); | |
1005 tj = TypeOopPtr::BOTTOM; | |
1006 ptr = tj->ptr(); | |
1007 offset = tj->offset(); | |
1008 } | |
1009 | |
1010 // Array pointers need some flattening | |
1011 const TypeAryPtr *ta = tj->isa_aryptr(); | |
1012 if( ta && _AliasLevel >= 2 ) { | |
1013 // For arrays indexed by constant indices, we flatten the alias | |
1014 // space to include all of the array body. Only the header, klass | |
1015 // and array length can be accessed un-aliased. | |
1016 if( offset != Type::OffsetBot ) { | |
1017 if( ta->const_oop() ) { // methodDataOop or methodOop | |
1018 offset = Type::OffsetBot; // Flatten constant access into array body | |
1019 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),ta->ary(),ta->klass(),false,Type::OffsetBot, ta->instance_id()); | |
1020 } else if( offset == arrayOopDesc::length_offset_in_bytes() ) { | |
1021 // range is OK as-is. | |
1022 tj = ta = TypeAryPtr::RANGE; | |
1023 } else if( offset == oopDesc::klass_offset_in_bytes() ) { | |
1024 tj = TypeInstPtr::KLASS; // all klass loads look alike | |
1025 ta = TypeAryPtr::RANGE; // generic ignored junk | |
1026 ptr = TypePtr::BotPTR; | |
1027 } else if( offset == oopDesc::mark_offset_in_bytes() ) { | |
1028 tj = TypeInstPtr::MARK; | |
1029 ta = TypeAryPtr::RANGE; // generic ignored junk | |
1030 ptr = TypePtr::BotPTR; | |
1031 } else { // Random constant offset into array body | |
1032 offset = Type::OffsetBot; // Flatten constant access into array body | |
1033 tj = ta = TypeAryPtr::make(ptr,ta->ary(),ta->klass(),false,Type::OffsetBot, ta->instance_id()); | |
1034 } | |
1035 } | |
1036 // Arrays of fixed size alias with arrays of unknown size. | |
1037 if (ta->size() != TypeInt::POS) { | |
1038 const TypeAry *tary = TypeAry::make(ta->elem(), TypeInt::POS); | |
1039 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,ta->klass(),false,offset, ta->instance_id()); | |
1040 } | |
1041 // Arrays of known objects become arrays of unknown objects. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
1042 if (ta->elem()->isa_narrowoop() && ta->elem() != TypeNarrowOop::BOTTOM) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
1043 const TypeAry *tary = TypeAry::make(TypeNarrowOop::BOTTOM, ta->size()); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
1044 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL,false,offset, ta->instance_id()); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
1045 } |
0 | 1046 if (ta->elem()->isa_oopptr() && ta->elem() != TypeInstPtr::BOTTOM) { |
1047 const TypeAry *tary = TypeAry::make(TypeInstPtr::BOTTOM, ta->size()); | |
1048 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL,false,offset, ta->instance_id()); | |
1049 } | |
1050 // Arrays of bytes and of booleans both use 'bastore' and 'baload' so | |
1051 // cannot be distinguished by bytecode alone. | |
1052 if (ta->elem() == TypeInt::BOOL) { | |
1053 const TypeAry *tary = TypeAry::make(TypeInt::BYTE, ta->size()); | |
1054 ciKlass* aklass = ciTypeArrayKlass::make(T_BYTE); | |
1055 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,aklass,false,offset, ta->instance_id()); | |
1056 } | |
1057 // During the 2nd round of IterGVN, NotNull castings are removed. | |
1058 // Make sure the Bottom and NotNull variants alias the same. | |
1059 // Also, make sure exact and non-exact variants alias the same. | |
1060 if( ptr == TypePtr::NotNull || ta->klass_is_exact() ) { | |
1061 if (ta->const_oop()) { | |
1062 tj = ta = TypeAryPtr::make(TypePtr::Constant,ta->const_oop(),ta->ary(),ta->klass(),false,offset); | |
1063 } else { | |
1064 tj = ta = TypeAryPtr::make(TypePtr::BotPTR,ta->ary(),ta->klass(),false,offset); | |
1065 } | |
1066 } | |
1067 } | |
1068 | |
1069 // Oop pointers need some flattening | |
1070 const TypeInstPtr *to = tj->isa_instptr(); | |
1071 if( to && _AliasLevel >= 2 && to != TypeOopPtr::BOTTOM ) { | |
1072 if( ptr == TypePtr::Constant ) { | |
1073 // No constant oop pointers (such as Strings); they alias with | |
1074 // unknown strings. | |
1075 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset); | |
223 | 1076 } else if( to->is_known_instance_field() ) { |
163 | 1077 tj = to; // Keep NotNull and klass_is_exact for instance type |
0 | 1078 } else if( ptr == TypePtr::NotNull || to->klass_is_exact() ) { |
1079 // During the 2nd round of IterGVN, NotNull castings are removed. | |
1080 // Make sure the Bottom and NotNull variants alias the same. | |
1081 // Also, make sure exact and non-exact variants alias the same. | |
1082 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset, to->instance_id()); | |
1083 } | |
1084 // Canonicalize the holder of this field | |
1085 ciInstanceKlass *k = to->klass()->as_instance_klass(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
1086 if (offset >= 0 && offset < instanceOopDesc::base_offset_in_bytes()) { |
0 | 1087 // First handle header references such as a LoadKlassNode, even if the |
1088 // object's klass is unloaded at compile time (4965979). | |
1089 tj = to = TypeInstPtr::make(TypePtr::BotPTR, env()->Object_klass(), false, NULL, offset, to->instance_id()); | |
1090 } else if (offset < 0 || offset >= k->size_helper() * wordSize) { | |
1091 to = NULL; | |
1092 tj = TypeOopPtr::BOTTOM; | |
1093 offset = tj->offset(); | |
1094 } else { | |
1095 ciInstanceKlass *canonical_holder = k->get_canonical_holder(offset); | |
1096 if (!k->equals(canonical_holder) || tj->offset() != offset) { | |
163 | 1097 tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, false, NULL, offset, to->instance_id()); |
0 | 1098 } |
1099 } | |
1100 } | |
1101 | |
1102 // Klass pointers to object array klasses need some flattening | |
1103 const TypeKlassPtr *tk = tj->isa_klassptr(); | |
1104 if( tk ) { | |
1105 // If we are referencing a field within a Klass, we need | |
1106 // to assume the worst case of an Object. Both exact and | |
1107 // inexact types must flatten to the same alias class. | |
1108 // Since the flattened result for a klass is defined to be | |
1109 // precisely java.lang.Object, use a constant ptr. | |
1110 if ( offset == Type::OffsetBot || (offset >= 0 && (size_t)offset < sizeof(Klass)) ) { | |
1111 | |
1112 tj = tk = TypeKlassPtr::make(TypePtr::Constant, | |
1113 TypeKlassPtr::OBJECT->klass(), | |
1114 offset); | |
1115 } | |
1116 | |
1117 ciKlass* klass = tk->klass(); | |
1118 if( klass->is_obj_array_klass() ) { | |
1119 ciKlass* k = TypeAryPtr::OOPS->klass(); | |
1120 if( !k || !k->is_loaded() ) // Only fails for some -Xcomp runs | |
1121 k = TypeInstPtr::BOTTOM->klass(); | |
1122 tj = tk = TypeKlassPtr::make( TypePtr::NotNull, k, offset ); | |
1123 } | |
1124 | |
1125 // Check for precise loads from the primary supertype array and force them | |
1126 // to the supertype cache alias index. Check for generic array loads from | |
1127 // the primary supertype array and also force them to the supertype cache | |
1128 // alias index. Since the same load can reach both, we need to merge | |
1129 // these 2 disparate memories into the same alias class. Since the | |
1130 // primary supertype array is read-only, there's no chance of confusion | |
1131 // where we bypass an array load and an array store. | |
1132 uint off2 = offset - Klass::primary_supers_offset_in_bytes(); | |
1133 if( offset == Type::OffsetBot || | |
1134 off2 < Klass::primary_super_limit()*wordSize ) { | |
1135 offset = sizeof(oopDesc) +Klass::secondary_super_cache_offset_in_bytes(); | |
1136 tj = tk = TypeKlassPtr::make( TypePtr::NotNull, tk->klass(), offset ); | |
1137 } | |
1138 } | |
1139 | |
1140 // Flatten all Raw pointers together. | |
1141 if (tj->base() == Type::RawPtr) | |
1142 tj = TypeRawPtr::BOTTOM; | |
1143 | |
1144 if (tj->base() == Type::AnyPtr) | |
1145 tj = TypePtr::BOTTOM; // An error, which the caller must check for. | |
1146 | |
1147 // Flatten all to bottom for now | |
1148 switch( _AliasLevel ) { | |
1149 case 0: | |
1150 tj = TypePtr::BOTTOM; | |
1151 break; | |
1152 case 1: // Flatten to: oop, static, field or array | |
1153 switch (tj->base()) { | |
1154 //case Type::AryPtr: tj = TypeAryPtr::RANGE; break; | |
1155 case Type::RawPtr: tj = TypeRawPtr::BOTTOM; break; | |
1156 case Type::AryPtr: // do not distinguish arrays at all | |
1157 case Type::InstPtr: tj = TypeInstPtr::BOTTOM; break; | |
1158 case Type::KlassPtr: tj = TypeKlassPtr::OBJECT; break; | |
1159 case Type::AnyPtr: tj = TypePtr::BOTTOM; break; // caller checks it | |
1160 default: ShouldNotReachHere(); | |
1161 } | |
1162 break; | |
1163 case 2: // No collasping at level 2; keep all splits | |
1164 case 3: // No collasping at level 3; keep all splits | |
1165 break; | |
1166 default: | |
1167 Unimplemented(); | |
1168 } | |
1169 | |
1170 offset = tj->offset(); | |
1171 assert( offset != Type::OffsetTop, "Offset has fallen from constant" ); | |
1172 | |
1173 assert( (offset != Type::OffsetBot && tj->base() != Type::AryPtr) || | |
1174 (offset == Type::OffsetBot && tj->base() == Type::AryPtr) || | |
1175 (offset == Type::OffsetBot && tj == TypeOopPtr::BOTTOM) || | |
1176 (offset == Type::OffsetBot && tj == TypePtr::BOTTOM) || | |
1177 (offset == oopDesc::mark_offset_in_bytes() && tj->base() == Type::AryPtr) || | |
1178 (offset == oopDesc::klass_offset_in_bytes() && tj->base() == Type::AryPtr) || | |
1179 (offset == arrayOopDesc::length_offset_in_bytes() && tj->base() == Type::AryPtr) , | |
1180 "For oops, klasses, raw offset must be constant; for arrays the offset is never known" ); | |
1181 assert( tj->ptr() != TypePtr::TopPTR && | |
1182 tj->ptr() != TypePtr::AnyNull && | |
1183 tj->ptr() != TypePtr::Null, "No imprecise addresses" ); | |
1184 // assert( tj->ptr() != TypePtr::Constant || | |
1185 // tj->base() == Type::RawPtr || | |
1186 // tj->base() == Type::KlassPtr, "No constant oop addresses" ); | |
1187 | |
1188 return tj; | |
1189 } | |
1190 | |
1191 void Compile::AliasType::Init(int i, const TypePtr* at) { | |
1192 _index = i; | |
1193 _adr_type = at; | |
1194 _field = NULL; | |
1195 _is_rewritable = true; // default | |
1196 const TypeOopPtr *atoop = (at != NULL) ? at->isa_oopptr() : NULL; | |
223 | 1197 if (atoop != NULL && atoop->is_known_instance()) { |
1198 const TypeOopPtr *gt = atoop->cast_to_instance_id(TypeOopPtr::InstanceBot); | |
0 | 1199 _general_index = Compile::current()->get_alias_index(gt); |
1200 } else { | |
1201 _general_index = 0; | |
1202 } | |
1203 } | |
1204 | |
1205 //---------------------------------print_on------------------------------------ | |
1206 #ifndef PRODUCT | |
1207 void Compile::AliasType::print_on(outputStream* st) { | |
1208 if (index() < 10) | |
1209 st->print("@ <%d> ", index()); | |
1210 else st->print("@ <%d>", index()); | |
1211 st->print(is_rewritable() ? " " : " RO"); | |
1212 int offset = adr_type()->offset(); | |
1213 if (offset == Type::OffsetBot) | |
1214 st->print(" +any"); | |
1215 else st->print(" +%-3d", offset); | |
1216 st->print(" in "); | |
1217 adr_type()->dump_on(st); | |
1218 const TypeOopPtr* tjp = adr_type()->isa_oopptr(); | |
1219 if (field() != NULL && tjp) { | |
1220 if (tjp->klass() != field()->holder() || | |
1221 tjp->offset() != field()->offset_in_bytes()) { | |
1222 st->print(" != "); | |
1223 field()->print(); | |
1224 st->print(" ***"); | |
1225 } | |
1226 } | |
1227 } | |
1228 | |
1229 void print_alias_types() { | |
1230 Compile* C = Compile::current(); | |
1231 tty->print_cr("--- Alias types, AliasIdxBot .. %d", C->num_alias_types()-1); | |
1232 for (int idx = Compile::AliasIdxBot; idx < C->num_alias_types(); idx++) { | |
1233 C->alias_type(idx)->print_on(tty); | |
1234 tty->cr(); | |
1235 } | |
1236 } | |
1237 #endif | |
1238 | |
1239 | |
1240 //----------------------------probe_alias_cache-------------------------------- | |
1241 Compile::AliasCacheEntry* Compile::probe_alias_cache(const TypePtr* adr_type) { | |
1242 intptr_t key = (intptr_t) adr_type; | |
1243 key ^= key >> logAliasCacheSize; | |
1244 return &_alias_cache[key & right_n_bits(logAliasCacheSize)]; | |
1245 } | |
1246 | |
1247 | |
1248 //-----------------------------grow_alias_types-------------------------------- | |
1249 void Compile::grow_alias_types() { | |
1250 const int old_ats = _max_alias_types; // how many before? | |
1251 const int new_ats = old_ats; // how many more? | |
1252 const int grow_ats = old_ats+new_ats; // how many now? | |
1253 _max_alias_types = grow_ats; | |
1254 _alias_types = REALLOC_ARENA_ARRAY(comp_arena(), AliasType*, _alias_types, old_ats, grow_ats); | |
1255 AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType, new_ats); | |
1256 Copy::zero_to_bytes(ats, sizeof(AliasType)*new_ats); | |
1257 for (int i = 0; i < new_ats; i++) _alias_types[old_ats+i] = &ats[i]; | |
1258 } | |
1259 | |
1260 | |
1261 //--------------------------------find_alias_type------------------------------ | |
1262 Compile::AliasType* Compile::find_alias_type(const TypePtr* adr_type, bool no_create) { | |
1263 if (_AliasLevel == 0) | |
1264 return alias_type(AliasIdxBot); | |
1265 | |
1266 AliasCacheEntry* ace = probe_alias_cache(adr_type); | |
1267 if (ace->_adr_type == adr_type) { | |
1268 return alias_type(ace->_index); | |
1269 } | |
1270 | |
1271 // Handle special cases. | |
1272 if (adr_type == NULL) return alias_type(AliasIdxTop); | |
1273 if (adr_type == TypePtr::BOTTOM) return alias_type(AliasIdxBot); | |
1274 | |
1275 // Do it the slow way. | |
1276 const TypePtr* flat = flatten_alias_type(adr_type); | |
1277 | |
1278 #ifdef ASSERT | |
1279 assert(flat == flatten_alias_type(flat), "idempotent"); | |
1280 assert(flat != TypePtr::BOTTOM, "cannot alias-analyze an untyped ptr"); | |
1281 if (flat->isa_oopptr() && !flat->isa_klassptr()) { | |
1282 const TypeOopPtr* foop = flat->is_oopptr(); | |
1283 const TypePtr* xoop = foop->cast_to_exactness(!foop->klass_is_exact())->is_ptr(); | |
1284 assert(foop == flatten_alias_type(xoop), "exactness must not affect alias type"); | |
1285 } | |
1286 assert(flat == flatten_alias_type(flat), "exact bit doesn't matter"); | |
1287 #endif | |
1288 | |
1289 int idx = AliasIdxTop; | |
1290 for (int i = 0; i < num_alias_types(); i++) { | |
1291 if (alias_type(i)->adr_type() == flat) { | |
1292 idx = i; | |
1293 break; | |
1294 } | |
1295 } | |
1296 | |
1297 if (idx == AliasIdxTop) { | |
1298 if (no_create) return NULL; | |
1299 // Grow the array if necessary. | |
1300 if (_num_alias_types == _max_alias_types) grow_alias_types(); | |
1301 // Add a new alias type. | |
1302 idx = _num_alias_types++; | |
1303 _alias_types[idx]->Init(idx, flat); | |
1304 if (flat == TypeInstPtr::KLASS) alias_type(idx)->set_rewritable(false); | |
1305 if (flat == TypeAryPtr::RANGE) alias_type(idx)->set_rewritable(false); | |
1306 if (flat->isa_instptr()) { | |
1307 if (flat->offset() == java_lang_Class::klass_offset_in_bytes() | |
1308 && flat->is_instptr()->klass() == env()->Class_klass()) | |
1309 alias_type(idx)->set_rewritable(false); | |
1310 } | |
1311 if (flat->isa_klassptr()) { | |
1312 if (flat->offset() == Klass::super_check_offset_offset_in_bytes() + (int)sizeof(oopDesc)) | |
1313 alias_type(idx)->set_rewritable(false); | |
1314 if (flat->offset() == Klass::modifier_flags_offset_in_bytes() + (int)sizeof(oopDesc)) | |
1315 alias_type(idx)->set_rewritable(false); | |
1316 if (flat->offset() == Klass::access_flags_offset_in_bytes() + (int)sizeof(oopDesc)) | |
1317 alias_type(idx)->set_rewritable(false); | |
1318 if (flat->offset() == Klass::java_mirror_offset_in_bytes() + (int)sizeof(oopDesc)) | |
1319 alias_type(idx)->set_rewritable(false); | |
1320 } | |
1321 // %%% (We would like to finalize JavaThread::threadObj_offset(), | |
1322 // but the base pointer type is not distinctive enough to identify | |
1323 // references into JavaThread.) | |
1324 | |
1325 // Check for final instance fields. | |
1326 const TypeInstPtr* tinst = flat->isa_instptr(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
1327 if (tinst && tinst->offset() >= instanceOopDesc::base_offset_in_bytes()) { |
0 | 1328 ciInstanceKlass *k = tinst->klass()->as_instance_klass(); |
1329 ciField* field = k->get_field_by_offset(tinst->offset(), false); | |
1330 // Set field() and is_rewritable() attributes. | |
1331 if (field != NULL) alias_type(idx)->set_field(field); | |
1332 } | |
1333 const TypeKlassPtr* tklass = flat->isa_klassptr(); | |
1334 // Check for final static fields. | |
1335 if (tklass && tklass->klass()->is_instance_klass()) { | |
1336 ciInstanceKlass *k = tklass->klass()->as_instance_klass(); | |
1337 ciField* field = k->get_field_by_offset(tklass->offset(), true); | |
1338 // Set field() and is_rewritable() attributes. | |
1339 if (field != NULL) alias_type(idx)->set_field(field); | |
1340 } | |
1341 } | |
1342 | |
1343 // Fill the cache for next time. | |
1344 ace->_adr_type = adr_type; | |
1345 ace->_index = idx; | |
1346 assert(alias_type(adr_type) == alias_type(idx), "type must be installed"); | |
1347 | |
1348 // Might as well try to fill the cache for the flattened version, too. | |
1349 AliasCacheEntry* face = probe_alias_cache(flat); | |
1350 if (face->_adr_type == NULL) { | |
1351 face->_adr_type = flat; | |
1352 face->_index = idx; | |
1353 assert(alias_type(flat) == alias_type(idx), "flat type must work too"); | |
1354 } | |
1355 | |
1356 return alias_type(idx); | |
1357 } | |
1358 | |
1359 | |
1360 Compile::AliasType* Compile::alias_type(ciField* field) { | |
1361 const TypeOopPtr* t; | |
1362 if (field->is_static()) | |
1363 t = TypeKlassPtr::make(field->holder()); | |
1364 else | |
1365 t = TypeOopPtr::make_from_klass_raw(field->holder()); | |
1366 AliasType* atp = alias_type(t->add_offset(field->offset_in_bytes())); | |
1367 assert(field->is_final() == !atp->is_rewritable(), "must get the rewritable bits correct"); | |
1368 return atp; | |
1369 } | |
1370 | |
1371 | |
1372 //------------------------------have_alias_type-------------------------------- | |
1373 bool Compile::have_alias_type(const TypePtr* adr_type) { | |
1374 AliasCacheEntry* ace = probe_alias_cache(adr_type); | |
1375 if (ace->_adr_type == adr_type) { | |
1376 return true; | |
1377 } | |
1378 | |
1379 // Handle special cases. | |
1380 if (adr_type == NULL) return true; | |
1381 if (adr_type == TypePtr::BOTTOM) return true; | |
1382 | |
1383 return find_alias_type(adr_type, true) != NULL; | |
1384 } | |
1385 | |
1386 //-----------------------------must_alias-------------------------------------- | |
1387 // True if all values of the given address type are in the given alias category. | |
1388 bool Compile::must_alias(const TypePtr* adr_type, int alias_idx) { | |
1389 if (alias_idx == AliasIdxBot) return true; // the universal category | |
1390 if (adr_type == NULL) return true; // NULL serves as TypePtr::TOP | |
1391 if (alias_idx == AliasIdxTop) return false; // the empty category | |
1392 if (adr_type->base() == Type::AnyPtr) return false; // TypePtr::BOTTOM or its twins | |
1393 | |
1394 // the only remaining possible overlap is identity | |
1395 int adr_idx = get_alias_index(adr_type); | |
1396 assert(adr_idx != AliasIdxBot && adr_idx != AliasIdxTop, ""); | |
1397 assert(adr_idx == alias_idx || | |
1398 (alias_type(alias_idx)->adr_type() != TypeOopPtr::BOTTOM | |
1399 && adr_type != TypeOopPtr::BOTTOM), | |
1400 "should not be testing for overlap with an unsafe pointer"); | |
1401 return adr_idx == alias_idx; | |
1402 } | |
1403 | |
1404 //------------------------------can_alias-------------------------------------- | |
1405 // True if any values of the given address type are in the given alias category. | |
1406 bool Compile::can_alias(const TypePtr* adr_type, int alias_idx) { | |
1407 if (alias_idx == AliasIdxTop) return false; // the empty category | |
1408 if (adr_type == NULL) return false; // NULL serves as TypePtr::TOP | |
1409 if (alias_idx == AliasIdxBot) return true; // the universal category | |
1410 if (adr_type->base() == Type::AnyPtr) return true; // TypePtr::BOTTOM or its twins | |
1411 | |
1412 // the only remaining possible overlap is identity | |
1413 int adr_idx = get_alias_index(adr_type); | |
1414 assert(adr_idx != AliasIdxBot && adr_idx != AliasIdxTop, ""); | |
1415 return adr_idx == alias_idx; | |
1416 } | |
1417 | |
1418 | |
1419 | |
1420 //---------------------------pop_warm_call------------------------------------- | |
1421 WarmCallInfo* Compile::pop_warm_call() { | |
1422 WarmCallInfo* wci = _warm_calls; | |
1423 if (wci != NULL) _warm_calls = wci->remove_from(wci); | |
1424 return wci; | |
1425 } | |
1426 | |
1427 //----------------------------Inline_Warm-------------------------------------- | |
1428 int Compile::Inline_Warm() { | |
1429 // If there is room, try to inline some more warm call sites. | |
1430 // %%% Do a graph index compaction pass when we think we're out of space? | |
1431 if (!InlineWarmCalls) return 0; | |
1432 | |
1433 int calls_made_hot = 0; | |
1434 int room_to_grow = NodeCountInliningCutoff - unique(); | |
1435 int amount_to_grow = MIN2(room_to_grow, (int)NodeCountInliningStep); | |
1436 int amount_grown = 0; | |
1437 WarmCallInfo* call; | |
1438 while (amount_to_grow > 0 && (call = pop_warm_call()) != NULL) { | |
1439 int est_size = (int)call->size(); | |
1440 if (est_size > (room_to_grow - amount_grown)) { | |
1441 // This one won't fit anyway. Get rid of it. | |
1442 call->make_cold(); | |
1443 continue; | |
1444 } | |
1445 call->make_hot(); | |
1446 calls_made_hot++; | |
1447 amount_grown += est_size; | |
1448 amount_to_grow -= est_size; | |
1449 } | |
1450 | |
1451 if (calls_made_hot > 0) set_major_progress(); | |
1452 return calls_made_hot; | |
1453 } | |
1454 | |
1455 | |
1456 //----------------------------Finish_Warm-------------------------------------- | |
1457 void Compile::Finish_Warm() { | |
1458 if (!InlineWarmCalls) return; | |
1459 if (failing()) return; | |
1460 if (warm_calls() == NULL) return; | |
1461 | |
1462 // Clean up loose ends, if we are out of space for inlining. | |
1463 WarmCallInfo* call; | |
1464 while ((call = pop_warm_call()) != NULL) { | |
1465 call->make_cold(); | |
1466 } | |
1467 } | |
1468 | |
1469 | |
1470 //------------------------------Optimize--------------------------------------- | |
1471 // Given a graph, optimize it. | |
1472 void Compile::Optimize() { | |
1473 TracePhase t1("optimizer", &_t_optimizer, true); | |
1474 | |
1475 #ifndef PRODUCT | |
1476 if (env()->break_at_compile()) { | |
1477 BREAKPOINT; | |
1478 } | |
1479 | |
1480 #endif | |
1481 | |
1482 ResourceMark rm; | |
1483 int loop_opts_cnt; | |
1484 | |
1485 NOT_PRODUCT( verify_graph_edges(); ) | |
1486 | |
222 | 1487 print_method("After Parsing"); |
0 | 1488 |
1489 { | |
1490 // Iterative Global Value Numbering, including ideal transforms | |
1491 // Initialize IterGVN with types and values from parse-time GVN | |
1492 PhaseIterGVN igvn(initial_gvn()); | |
1493 { | |
1494 NOT_PRODUCT( TracePhase t2("iterGVN", &_t_iterGVN, TimeCompiler); ) | |
1495 igvn.optimize(); | |
1496 } | |
1497 | |
1498 print_method("Iter GVN 1", 2); | |
1499 | |
1500 if (failing()) return; | |
1501 | |
1502 // get rid of the connection graph since it's information is not | |
1503 // updated by optimizations | |
1504 _congraph = NULL; | |
1505 | |
1506 | |
1507 // Loop transforms on the ideal graph. Range Check Elimination, | |
1508 // peeling, unrolling, etc. | |
1509 | |
1510 // Set loop opts counter | |
1511 loop_opts_cnt = num_loop_opts(); | |
1512 if((loop_opts_cnt > 0) && (has_loops() || has_split_ifs())) { | |
1513 { | |
1514 TracePhase t2("idealLoop", &_t_idealLoop, true); | |
1515 PhaseIdealLoop ideal_loop( igvn, NULL, true ); | |
1516 loop_opts_cnt--; | |
1517 if (major_progress()) print_method("PhaseIdealLoop 1", 2); | |
1518 if (failing()) return; | |
1519 } | |
1520 // Loop opts pass if partial peeling occurred in previous pass | |
1521 if(PartialPeelLoop && major_progress() && (loop_opts_cnt > 0)) { | |
1522 TracePhase t3("idealLoop", &_t_idealLoop, true); | |
1523 PhaseIdealLoop ideal_loop( igvn, NULL, false ); | |
1524 loop_opts_cnt--; | |
1525 if (major_progress()) print_method("PhaseIdealLoop 2", 2); | |
1526 if (failing()) return; | |
1527 } | |
1528 // Loop opts pass for loop-unrolling before CCP | |
1529 if(major_progress() && (loop_opts_cnt > 0)) { | |
1530 TracePhase t4("idealLoop", &_t_idealLoop, true); | |
1531 PhaseIdealLoop ideal_loop( igvn, NULL, false ); | |
1532 loop_opts_cnt--; | |
1533 if (major_progress()) print_method("PhaseIdealLoop 3", 2); | |
1534 } | |
1535 } | |
1536 if (failing()) return; | |
1537 | |
1538 // Conditional Constant Propagation; | |
1539 PhaseCCP ccp( &igvn ); | |
1540 assert( true, "Break here to ccp.dump_nodes_and_types(_root,999,1)"); | |
1541 { | |
1542 TracePhase t2("ccp", &_t_ccp, true); | |
1543 ccp.do_transform(); | |
1544 } | |
1545 print_method("PhaseCPP 1", 2); | |
1546 | |
1547 assert( true, "Break here to ccp.dump_old2new_map()"); | |
1548 | |
1549 // Iterative Global Value Numbering, including ideal transforms | |
1550 { | |
1551 NOT_PRODUCT( TracePhase t2("iterGVN2", &_t_iterGVN2, TimeCompiler); ) | |
1552 igvn = ccp; | |
1553 igvn.optimize(); | |
1554 } | |
1555 | |
1556 print_method("Iter GVN 2", 2); | |
1557 | |
1558 if (failing()) return; | |
1559 | |
1560 // Loop transforms on the ideal graph. Range Check Elimination, | |
1561 // peeling, unrolling, etc. | |
1562 if(loop_opts_cnt > 0) { | |
1563 debug_only( int cnt = 0; ); | |
1564 while(major_progress() && (loop_opts_cnt > 0)) { | |
1565 TracePhase t2("idealLoop", &_t_idealLoop, true); | |
1566 assert( cnt++ < 40, "infinite cycle in loop optimization" ); | |
1567 PhaseIdealLoop ideal_loop( igvn, NULL, true ); | |
1568 loop_opts_cnt--; | |
1569 if (major_progress()) print_method("PhaseIdealLoop iterations", 2); | |
1570 if (failing()) return; | |
1571 } | |
1572 } | |
1573 { | |
1574 NOT_PRODUCT( TracePhase t2("macroExpand", &_t_macroExpand, TimeCompiler); ) | |
1575 PhaseMacroExpand mex(igvn); | |
1576 if (mex.expand_macro_nodes()) { | |
1577 assert(failing(), "must bail out w/ explicit message"); | |
1578 return; | |
1579 } | |
1580 } | |
1581 | |
1582 } // (End scope of igvn; run destructor if necessary for asserts.) | |
1583 | |
1584 // A method with only infinite loops has no edges entering loops from root | |
1585 { | |
1586 NOT_PRODUCT( TracePhase t2("graphReshape", &_t_graphReshaping, TimeCompiler); ) | |
1587 if (final_graph_reshaping()) { | |
1588 assert(failing(), "must bail out w/ explicit message"); | |
1589 return; | |
1590 } | |
1591 } | |
1592 | |
1593 print_method("Optimize finished", 2); | |
1594 } | |
1595 | |
1596 | |
1597 //------------------------------Code_Gen--------------------------------------- | |
1598 // Given a graph, generate code for it | |
1599 void Compile::Code_Gen() { | |
1600 if (failing()) return; | |
1601 | |
1602 // Perform instruction selection. You might think we could reclaim Matcher | |
1603 // memory PDQ, but actually the Matcher is used in generating spill code. | |
1604 // Internals of the Matcher (including some VectorSets) must remain live | |
1605 // for awhile - thus I cannot reclaim Matcher memory lest a VectorSet usage | |
1606 // set a bit in reclaimed memory. | |
1607 | |
1608 // In debug mode can dump m._nodes.dump() for mapping of ideal to machine | |
1609 // nodes. Mapping is only valid at the root of each matched subtree. | |
1610 NOT_PRODUCT( verify_graph_edges(); ) | |
1611 | |
1612 Node_List proj_list; | |
1613 Matcher m(proj_list); | |
1614 _matcher = &m; | |
1615 { | |
1616 TracePhase t2("matcher", &_t_matcher, true); | |
1617 m.match(); | |
1618 } | |
1619 // In debug mode can dump m._nodes.dump() for mapping of ideal to machine | |
1620 // nodes. Mapping is only valid at the root of each matched subtree. | |
1621 NOT_PRODUCT( verify_graph_edges(); ) | |
1622 | |
1623 // If you have too many nodes, or if matching has failed, bail out | |
1624 check_node_count(0, "out of nodes matching instructions"); | |
1625 if (failing()) return; | |
1626 | |
1627 // Build a proper-looking CFG | |
1628 PhaseCFG cfg(node_arena(), root(), m); | |
1629 _cfg = &cfg; | |
1630 { | |
1631 NOT_PRODUCT( TracePhase t2("scheduler", &_t_scheduler, TimeCompiler); ) | |
1632 cfg.Dominators(); | |
1633 if (failing()) return; | |
1634 | |
1635 NOT_PRODUCT( verify_graph_edges(); ) | |
1636 | |
1637 cfg.Estimate_Block_Frequency(); | |
1638 cfg.GlobalCodeMotion(m,unique(),proj_list); | |
1639 | |
1640 print_method("Global code motion", 2); | |
1641 | |
1642 if (failing()) return; | |
1643 NOT_PRODUCT( verify_graph_edges(); ) | |
1644 | |
1645 debug_only( cfg.verify(); ) | |
1646 } | |
1647 NOT_PRODUCT( verify_graph_edges(); ) | |
1648 | |
1649 PhaseChaitin regalloc(unique(),cfg,m); | |
1650 _regalloc = ®alloc; | |
1651 { | |
1652 TracePhase t2("regalloc", &_t_registerAllocation, true); | |
1653 // Perform any platform dependent preallocation actions. This is used, | |
1654 // for example, to avoid taking an implicit null pointer exception | |
1655 // using the frame pointer on win95. | |
1656 _regalloc->pd_preallocate_hook(); | |
1657 | |
1658 // Perform register allocation. After Chaitin, use-def chains are | |
1659 // no longer accurate (at spill code) and so must be ignored. | |
1660 // Node->LRG->reg mappings are still accurate. | |
1661 _regalloc->Register_Allocate(); | |
1662 | |
1663 // Bail out if the allocator builds too many nodes | |
1664 if (failing()) return; | |
1665 } | |
1666 | |
1667 // Prior to register allocation we kept empty basic blocks in case the | |
1668 // the allocator needed a place to spill. After register allocation we | |
1669 // are not adding any new instructions. If any basic block is empty, we | |
1670 // can now safely remove it. | |
1671 { | |
1672 NOT_PRODUCT( TracePhase t2("removeEmpty", &_t_removeEmptyBlocks, TimeCompiler); ) | |
1673 cfg.RemoveEmpty(); | |
1674 } | |
1675 | |
1676 // Perform any platform dependent postallocation verifications. | |
1677 debug_only( _regalloc->pd_postallocate_verify_hook(); ) | |
1678 | |
1679 // Apply peephole optimizations | |
1680 if( OptoPeephole ) { | |
1681 NOT_PRODUCT( TracePhase t2("peephole", &_t_peephole, TimeCompiler); ) | |
1682 PhasePeephole peep( _regalloc, cfg); | |
1683 peep.do_transform(); | |
1684 } | |
1685 | |
1686 // Convert Nodes to instruction bits in a buffer | |
1687 { | |
1688 // %%%% workspace merge brought two timers together for one job | |
1689 TracePhase t2a("output", &_t_output, true); | |
1690 NOT_PRODUCT( TraceTime t2b(NULL, &_t_codeGeneration, TimeCompiler, false); ) | |
1691 Output(); | |
1692 } | |
1693 | |
222 | 1694 print_method("Final Code"); |
0 | 1695 |
1696 // He's dead, Jim. | |
1697 _cfg = (PhaseCFG*)0xdeadbeef; | |
1698 _regalloc = (PhaseChaitin*)0xdeadbeef; | |
1699 } | |
1700 | |
1701 | |
1702 //------------------------------dump_asm--------------------------------------- | |
1703 // Dump formatted assembly | |
1704 #ifndef PRODUCT | |
1705 void Compile::dump_asm(int *pcs, uint pc_limit) { | |
1706 bool cut_short = false; | |
1707 tty->print_cr("#"); | |
1708 tty->print("# "); _tf->dump(); tty->cr(); | |
1709 tty->print_cr("#"); | |
1710 | |
1711 // For all blocks | |
1712 int pc = 0x0; // Program counter | |
1713 char starts_bundle = ' '; | |
1714 _regalloc->dump_frame(); | |
1715 | |
1716 Node *n = NULL; | |
1717 for( uint i=0; i<_cfg->_num_blocks; i++ ) { | |
1718 if (VMThread::should_terminate()) { cut_short = true; break; } | |
1719 Block *b = _cfg->_blocks[i]; | |
1720 if (b->is_connector() && !Verbose) continue; | |
1721 n = b->_nodes[0]; | |
1722 if (pcs && n->_idx < pc_limit) | |
1723 tty->print("%3.3x ", pcs[n->_idx]); | |
1724 else | |
1725 tty->print(" "); | |
1726 b->dump_head( &_cfg->_bbs ); | |
1727 if (b->is_connector()) { | |
1728 tty->print_cr(" # Empty connector block"); | |
1729 } else if (b->num_preds() == 2 && b->pred(1)->is_CatchProj() && b->pred(1)->as_CatchProj()->_con == CatchProjNode::fall_through_index) { | |
1730 tty->print_cr(" # Block is sole successor of call"); | |
1731 } | |
1732 | |
1733 // For all instructions | |
1734 Node *delay = NULL; | |
1735 for( uint j = 0; j<b->_nodes.size(); j++ ) { | |
1736 if (VMThread::should_terminate()) { cut_short = true; break; } | |
1737 n = b->_nodes[j]; | |
1738 if (valid_bundle_info(n)) { | |
1739 Bundle *bundle = node_bundling(n); | |
1740 if (bundle->used_in_unconditional_delay()) { | |
1741 delay = n; | |
1742 continue; | |
1743 } | |
1744 if (bundle->starts_bundle()) | |
1745 starts_bundle = '+'; | |
1746 } | |
1747 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
1748 if (WizardMode) n->dump(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
1749 |
0 | 1750 if( !n->is_Region() && // Dont print in the Assembly |
1751 !n->is_Phi() && // a few noisely useless nodes | |
1752 !n->is_Proj() && | |
1753 !n->is_MachTemp() && | |
1754 !n->is_Catch() && // Would be nice to print exception table targets | |
1755 !n->is_MergeMem() && // Not very interesting | |
1756 !n->is_top() && // Debug info table constants | |
1757 !(n->is_Con() && !n->is_Mach())// Debug info table constants | |
1758 ) { | |
1759 if (pcs && n->_idx < pc_limit) | |
1760 tty->print("%3.3x", pcs[n->_idx]); | |
1761 else | |
1762 tty->print(" "); | |
1763 tty->print(" %c ", starts_bundle); | |
1764 starts_bundle = ' '; | |
1765 tty->print("\t"); | |
1766 n->format(_regalloc, tty); | |
1767 tty->cr(); | |
1768 } | |
1769 | |
1770 // If we have an instruction with a delay slot, and have seen a delay, | |
1771 // then back up and print it | |
1772 if (valid_bundle_info(n) && node_bundling(n)->use_unconditional_delay()) { | |
1773 assert(delay != NULL, "no unconditional delay instruction"); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
1774 if (WizardMode) delay->dump(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
1775 |
0 | 1776 if (node_bundling(delay)->starts_bundle()) |
1777 starts_bundle = '+'; | |
1778 if (pcs && n->_idx < pc_limit) | |
1779 tty->print("%3.3x", pcs[n->_idx]); | |
1780 else | |
1781 tty->print(" "); | |
1782 tty->print(" %c ", starts_bundle); | |
1783 starts_bundle = ' '; | |
1784 tty->print("\t"); | |
1785 delay->format(_regalloc, tty); | |
1786 tty->print_cr(""); | |
1787 delay = NULL; | |
1788 } | |
1789 | |
1790 // Dump the exception table as well | |
1791 if( n->is_Catch() && (Verbose || WizardMode) ) { | |
1792 // Print the exception table for this offset | |
1793 _handler_table.print_subtable_for(pc); | |
1794 } | |
1795 } | |
1796 | |
1797 if (pcs && n->_idx < pc_limit) | |
1798 tty->print_cr("%3.3x", pcs[n->_idx]); | |
1799 else | |
1800 tty->print_cr(""); | |
1801 | |
1802 assert(cut_short || delay == NULL, "no unconditional delay branch"); | |
1803 | |
1804 } // End of per-block dump | |
1805 tty->print_cr(""); | |
1806 | |
1807 if (cut_short) tty->print_cr("*** disassembly is cut short ***"); | |
1808 } | |
1809 #endif | |
1810 | |
1811 //------------------------------Final_Reshape_Counts--------------------------- | |
1812 // This class defines counters to help identify when a method | |
1813 // may/must be executed using hardware with only 24-bit precision. | |
1814 struct Final_Reshape_Counts : public StackObj { | |
1815 int _call_count; // count non-inlined 'common' calls | |
1816 int _float_count; // count float ops requiring 24-bit precision | |
1817 int _double_count; // count double ops requiring more precision | |
1818 int _java_call_count; // count non-inlined 'java' calls | |
1819 VectorSet _visited; // Visitation flags | |
1820 Node_List _tests; // Set of IfNodes & PCTableNodes | |
1821 | |
1822 Final_Reshape_Counts() : | |
1823 _call_count(0), _float_count(0), _double_count(0), _java_call_count(0), | |
1824 _visited( Thread::current()->resource_area() ) { } | |
1825 | |
1826 void inc_call_count () { _call_count ++; } | |
1827 void inc_float_count () { _float_count ++; } | |
1828 void inc_double_count() { _double_count++; } | |
1829 void inc_java_call_count() { _java_call_count++; } | |
1830 | |
1831 int get_call_count () const { return _call_count ; } | |
1832 int get_float_count () const { return _float_count ; } | |
1833 int get_double_count() const { return _double_count; } | |
1834 int get_java_call_count() const { return _java_call_count; } | |
1835 }; | |
1836 | |
1837 static bool oop_offset_is_sane(const TypeInstPtr* tp) { | |
1838 ciInstanceKlass *k = tp->klass()->as_instance_klass(); | |
1839 // Make sure the offset goes inside the instance layout. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
1840 return k->contains_field_offset(tp->offset()); |
0 | 1841 // Note that OffsetBot and OffsetTop are very negative. |
1842 } | |
1843 | |
1844 //------------------------------final_graph_reshaping_impl---------------------- | |
1845 // Implement items 1-5 from final_graph_reshaping below. | |
1846 static void final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &fpu ) { | |
1847 | |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
1848 if ( n->outcnt() == 0 ) return; // dead node |
0 | 1849 uint nop = n->Opcode(); |
1850 | |
1851 // Check for 2-input instruction with "last use" on right input. | |
1852 // Swap to left input. Implements item (2). | |
1853 if( n->req() == 3 && // two-input instruction | |
1854 n->in(1)->outcnt() > 1 && // left use is NOT a last use | |
1855 (!n->in(1)->is_Phi() || n->in(1)->in(2) != n) && // it is not data loop | |
1856 n->in(2)->outcnt() == 1 &&// right use IS a last use | |
1857 !n->in(2)->is_Con() ) { // right use is not a constant | |
1858 // Check for commutative opcode | |
1859 switch( nop ) { | |
1860 case Op_AddI: case Op_AddF: case Op_AddD: case Op_AddL: | |
1861 case Op_MaxI: case Op_MinI: | |
1862 case Op_MulI: case Op_MulF: case Op_MulD: case Op_MulL: | |
1863 case Op_AndL: case Op_XorL: case Op_OrL: | |
1864 case Op_AndI: case Op_XorI: case Op_OrI: { | |
1865 // Move "last use" input to left by swapping inputs | |
1866 n->swap_edges(1, 2); | |
1867 break; | |
1868 } | |
1869 default: | |
1870 break; | |
1871 } | |
1872 } | |
1873 | |
1874 // Count FPU ops and common calls, implements item (3) | |
1875 switch( nop ) { | |
1876 // Count all float operations that may use FPU | |
1877 case Op_AddF: | |
1878 case Op_SubF: | |
1879 case Op_MulF: | |
1880 case Op_DivF: | |
1881 case Op_NegF: | |
1882 case Op_ModF: | |
1883 case Op_ConvI2F: | |
1884 case Op_ConF: | |
1885 case Op_CmpF: | |
1886 case Op_CmpF3: | |
1887 // case Op_ConvL2F: // longs are split into 32-bit halves | |
1888 fpu.inc_float_count(); | |
1889 break; | |
1890 | |
1891 case Op_ConvF2D: | |
1892 case Op_ConvD2F: | |
1893 fpu.inc_float_count(); | |
1894 fpu.inc_double_count(); | |
1895 break; | |
1896 | |
1897 // Count all double operations that may use FPU | |
1898 case Op_AddD: | |
1899 case Op_SubD: | |
1900 case Op_MulD: | |
1901 case Op_DivD: | |
1902 case Op_NegD: | |
1903 case Op_ModD: | |
1904 case Op_ConvI2D: | |
1905 case Op_ConvD2I: | |
1906 // case Op_ConvL2D: // handled by leaf call | |
1907 // case Op_ConvD2L: // handled by leaf call | |
1908 case Op_ConD: | |
1909 case Op_CmpD: | |
1910 case Op_CmpD3: | |
1911 fpu.inc_double_count(); | |
1912 break; | |
1913 case Op_Opaque1: // Remove Opaque Nodes before matching | |
1914 case Op_Opaque2: // Remove Opaque Nodes before matching | |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
1915 n->subsume_by(n->in(1)); |
0 | 1916 break; |
1917 case Op_CallStaticJava: | |
1918 case Op_CallJava: | |
1919 case Op_CallDynamicJava: | |
1920 fpu.inc_java_call_count(); // Count java call site; | |
1921 case Op_CallRuntime: | |
1922 case Op_CallLeaf: | |
1923 case Op_CallLeafNoFP: { | |
1924 assert( n->is_Call(), "" ); | |
1925 CallNode *call = n->as_Call(); | |
1926 // Count call sites where the FP mode bit would have to be flipped. | |
1927 // Do not count uncommon runtime calls: | |
1928 // uncommon_trap, _complete_monitor_locking, _complete_monitor_unlocking, | |
1929 // _new_Java, _new_typeArray, _new_objArray, _rethrow_Java, ... | |
1930 if( !call->is_CallStaticJava() || !call->as_CallStaticJava()->_name ) { | |
1931 fpu.inc_call_count(); // Count the call site | |
1932 } else { // See if uncommon argument is shared | |
1933 Node *n = call->in(TypeFunc::Parms); | |
1934 int nop = n->Opcode(); | |
1935 // Clone shared simple arguments to uncommon calls, item (1). | |
1936 if( n->outcnt() > 1 && | |
1937 !n->is_Proj() && | |
1938 nop != Op_CreateEx && | |
1939 nop != Op_CheckCastPP && | |
1940 !n->is_Mem() ) { | |
1941 Node *x = n->clone(); | |
1942 call->set_req( TypeFunc::Parms, x ); | |
1943 } | |
1944 } | |
1945 break; | |
1946 } | |
1947 | |
1948 case Op_StoreD: | |
1949 case Op_LoadD: | |
1950 case Op_LoadD_unaligned: | |
1951 fpu.inc_double_count(); | |
1952 goto handle_mem; | |
1953 case Op_StoreF: | |
1954 case Op_LoadF: | |
1955 fpu.inc_float_count(); | |
1956 goto handle_mem; | |
1957 | |
1958 case Op_StoreB: | |
1959 case Op_StoreC: | |
1960 case Op_StoreCM: | |
1961 case Op_StorePConditional: | |
1962 case Op_StoreI: | |
1963 case Op_StoreL: | |
1964 case Op_StoreLConditional: | |
1965 case Op_CompareAndSwapI: | |
1966 case Op_CompareAndSwapL: | |
1967 case Op_CompareAndSwapP: | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
1968 case Op_CompareAndSwapN: |
0 | 1969 case Op_StoreP: |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
1970 case Op_StoreN: |
0 | 1971 case Op_LoadB: |
1972 case Op_LoadC: | |
1973 case Op_LoadI: | |
1974 case Op_LoadKlass: | |
164
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
1975 case Op_LoadNKlass: |
0 | 1976 case Op_LoadL: |
1977 case Op_LoadL_unaligned: | |
1978 case Op_LoadPLocked: | |
1979 case Op_LoadLLocked: | |
1980 case Op_LoadP: | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
1981 case Op_LoadN: |
0 | 1982 case Op_LoadRange: |
1983 case Op_LoadS: { | |
1984 handle_mem: | |
1985 #ifdef ASSERT | |
1986 if( VerifyOptoOopOffsets ) { | |
1987 assert( n->is_Mem(), "" ); | |
1988 MemNode *mem = (MemNode*)n; | |
1989 // Check to see if address types have grounded out somehow. | |
1990 const TypeInstPtr *tp = mem->in(MemNode::Address)->bottom_type()->isa_instptr(); | |
1991 assert( !tp || oop_offset_is_sane(tp), "" ); | |
1992 } | |
1993 #endif | |
1994 break; | |
1995 } | |
1996 | |
1997 case Op_AddP: { // Assert sane base pointers | |
182
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
1998 Node *addp = n->in(AddPNode::Address); |
0 | 1999 assert( !addp->is_AddP() || |
2000 addp->in(AddPNode::Base)->is_top() || // Top OK for allocation | |
2001 addp->in(AddPNode::Base) == n->in(AddPNode::Base), | |
2002 "Base pointers must match" ); | |
182
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2003 #ifdef _LP64 |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2004 if (UseCompressedOops && |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2005 addp->Opcode() == Op_ConP && |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2006 addp == n->in(AddPNode::Base) && |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2007 n->in(AddPNode::Offset)->is_Con()) { |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2008 // Use addressing with narrow klass to load with offset on x86. |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2009 // On sparc loading 32-bits constant and decoding it have less |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2010 // instructions (4) then load 64-bits constant (7). |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2011 // Do this transformation here since IGVN will convert ConN back to ConP. |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2012 const Type* t = addp->bottom_type(); |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2013 if (t->isa_oopptr()) { |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2014 Node* nn = NULL; |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2015 |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2016 // Look for existing ConN node of the same exact type. |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2017 Compile* C = Compile::current(); |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2018 Node* r = C->root(); |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2019 uint cnt = r->outcnt(); |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2020 for (uint i = 0; i < cnt; i++) { |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2021 Node* m = r->raw_out(i); |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2022 if (m!= NULL && m->Opcode() == Op_ConN && |
221
1e026f8da827
6710487: More than half of JDI Regression tests hang with COOPs in -Xcomp mode
kvn
parents:
182
diff
changeset
|
2023 m->bottom_type()->make_ptr() == t) { |
182
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2024 nn = m; |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2025 break; |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2026 } |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2027 } |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2028 if (nn != NULL) { |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2029 // Decode a narrow oop to match address |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2030 // [R12 + narrow_oop_reg<<3 + offset] |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2031 nn = new (C, 2) DecodeNNode(nn, t); |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2032 n->set_req(AddPNode::Base, nn); |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2033 n->set_req(AddPNode::Address, nn); |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2034 if (addp->outcnt() == 0) { |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2035 addp->disconnect_inputs(NULL); |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2036 } |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2037 } |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2038 } |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2039 } |
44abbb0d4c18
6709093: Compressed Oops: reduce size of compiled methods
kvn
parents:
168
diff
changeset
|
2040 #endif |
0 | 2041 break; |
2042 } | |
2043 | |
164
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2044 #ifdef _LP64 |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2045 case Op_CmpP: |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2046 // Do this transformation here to preserve CmpPNode::sub() and |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2047 // other TypePtr related Ideal optimizations (for example, ptr nullness). |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2048 if( n->in(1)->is_DecodeN() ) { |
164
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2049 Compile* C = Compile::current(); |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2050 Node* in2 = NULL; |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2051 if( n->in(2)->is_DecodeN() ) { |
164
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2052 in2 = n->in(2)->in(1); |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2053 } else if ( n->in(2)->Opcode() == Op_ConP ) { |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2054 const Type* t = n->in(2)->bottom_type(); |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2055 if (t == TypePtr::NULL_PTR) { |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2056 Node *in1 = n->in(1); |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2057 if (Matcher::clone_shift_expressions) { |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2058 // x86, ARM and friends can handle 2 adds in addressing mode. |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2059 // Decode a narrow oop and do implicit NULL check in address |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2060 // [R12 + narrow_oop_reg<<3 + offset] |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2061 in2 = ConNode::make(C, TypeNarrowOop::NULL_PTR); |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2062 } else { |
164
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2063 // Don't replace CmpP(o ,null) if 'o' is used in AddP |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2064 // to generate implicit NULL check on Sparc where |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2065 // narrow oops can't be used in address. |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2066 uint i = 0; |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2067 for (; i < in1->outcnt(); i++) { |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2068 if (in1->raw_out(i)->is_AddP()) |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2069 break; |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2070 } |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2071 if (i >= in1->outcnt()) { |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2072 in2 = ConNode::make(C, TypeNarrowOop::NULL_PTR); |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2073 } |
164
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2074 } |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2075 } else if (t->isa_oopptr()) { |
221
1e026f8da827
6710487: More than half of JDI Regression tests hang with COOPs in -Xcomp mode
kvn
parents:
182
diff
changeset
|
2076 in2 = ConNode::make(C, t->make_narrowoop()); |
164
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2077 } |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2078 } |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2079 if( in2 != NULL ) { |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2080 Node* cmpN = new (C, 3) CmpNNode(n->in(1)->in(1), in2); |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2081 n->subsume_by( cmpN ); |
164
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2082 } |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2083 } |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2084 #endif |
c436414a719e
6703890: Compressed Oops: add LoadNKlass node to generate narrow oops (32-bits) compare instructions
kvn
parents:
163
diff
changeset
|
2085 |
0 | 2086 case Op_ModI: |
2087 if (UseDivMod) { | |
2088 // Check if a%b and a/b both exist | |
2089 Node* d = n->find_similar(Op_DivI); | |
2090 if (d) { | |
2091 // Replace them with a fused divmod if supported | |
2092 Compile* C = Compile::current(); | |
2093 if (Matcher::has_match_rule(Op_DivModI)) { | |
2094 DivModINode* divmod = DivModINode::make(C, n); | |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2095 d->subsume_by(divmod->div_proj()); |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2096 n->subsume_by(divmod->mod_proj()); |
0 | 2097 } else { |
2098 // replace a%b with a-((a/b)*b) | |
2099 Node* mult = new (C, 3) MulINode(d, d->in(2)); | |
2100 Node* sub = new (C, 3) SubINode(d->in(1), mult); | |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2101 n->subsume_by( sub ); |
0 | 2102 } |
2103 } | |
2104 } | |
2105 break; | |
2106 | |
2107 case Op_ModL: | |
2108 if (UseDivMod) { | |
2109 // Check if a%b and a/b both exist | |
2110 Node* d = n->find_similar(Op_DivL); | |
2111 if (d) { | |
2112 // Replace them with a fused divmod if supported | |
2113 Compile* C = Compile::current(); | |
2114 if (Matcher::has_match_rule(Op_DivModL)) { | |
2115 DivModLNode* divmod = DivModLNode::make(C, n); | |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2116 d->subsume_by(divmod->div_proj()); |
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2117 n->subsume_by(divmod->mod_proj()); |
0 | 2118 } else { |
2119 // replace a%b with a-((a/b)*b) | |
2120 Node* mult = new (C, 3) MulLNode(d, d->in(2)); | |
2121 Node* sub = new (C, 3) SubLNode(d->in(1), mult); | |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2122 n->subsume_by( sub ); |
0 | 2123 } |
2124 } | |
2125 } | |
2126 break; | |
2127 | |
2128 case Op_Load16B: | |
2129 case Op_Load8B: | |
2130 case Op_Load4B: | |
2131 case Op_Load8S: | |
2132 case Op_Load4S: | |
2133 case Op_Load2S: | |
2134 case Op_Load8C: | |
2135 case Op_Load4C: | |
2136 case Op_Load2C: | |
2137 case Op_Load4I: | |
2138 case Op_Load2I: | |
2139 case Op_Load2L: | |
2140 case Op_Load4F: | |
2141 case Op_Load2F: | |
2142 case Op_Load2D: | |
2143 case Op_Store16B: | |
2144 case Op_Store8B: | |
2145 case Op_Store4B: | |
2146 case Op_Store8C: | |
2147 case Op_Store4C: | |
2148 case Op_Store2C: | |
2149 case Op_Store4I: | |
2150 case Op_Store2I: | |
2151 case Op_Store2L: | |
2152 case Op_Store4F: | |
2153 case Op_Store2F: | |
2154 case Op_Store2D: | |
2155 break; | |
2156 | |
2157 case Op_PackB: | |
2158 case Op_PackS: | |
2159 case Op_PackC: | |
2160 case Op_PackI: | |
2161 case Op_PackF: | |
2162 case Op_PackL: | |
2163 case Op_PackD: | |
2164 if (n->req()-1 > 2) { | |
2165 // Replace many operand PackNodes with a binary tree for matching | |
2166 PackNode* p = (PackNode*) n; | |
2167 Node* btp = p->binaryTreePack(Compile::current(), 1, n->req()); | |
168
7793bd37a336
6705887: Compressed Oops: generate x64 addressing and implicit null checks with narrow oops
kvn
parents:
164
diff
changeset
|
2168 n->subsume_by(btp); |
0 | 2169 } |
2170 break; | |
2171 default: | |
2172 assert( !n->is_Call(), "" ); | |
2173 assert( !n->is_Mem(), "" ); | |
2174 break; | |
2175 } | |
127 | 2176 |
2177 // Collect CFG split points | |
2178 if (n->is_MultiBranch()) | |
2179 fpu._tests.push(n); | |
0 | 2180 } |
2181 | |
2182 //------------------------------final_graph_reshaping_walk--------------------- | |
2183 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(), | |
2184 // requires that the walk visits a node's inputs before visiting the node. | |
2185 static void final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &fpu ) { | |
2186 fpu._visited.set(root->_idx); // first, mark node as visited | |
2187 uint cnt = root->req(); | |
2188 Node *n = root; | |
2189 uint i = 0; | |
2190 while (true) { | |
2191 if (i < cnt) { | |
2192 // Place all non-visited non-null inputs onto stack | |
2193 Node* m = n->in(i); | |
2194 ++i; | |
2195 if (m != NULL && !fpu._visited.test_set(m->_idx)) { | |
2196 cnt = m->req(); | |
2197 nstack.push(n, i); // put on stack parent and next input's index | |
2198 n = m; | |
2199 i = 0; | |
2200 } | |
2201 } else { | |
2202 // Now do post-visit work | |
2203 final_graph_reshaping_impl( n, fpu ); | |
2204 if (nstack.is_empty()) | |
2205 break; // finished | |
2206 n = nstack.node(); // Get node from stack | |
2207 cnt = n->req(); | |
2208 i = nstack.index(); | |
2209 nstack.pop(); // Shift to the next node on stack | |
2210 } | |
2211 } | |
2212 } | |
2213 | |
2214 //------------------------------final_graph_reshaping-------------------------- | |
2215 // Final Graph Reshaping. | |
2216 // | |
2217 // (1) Clone simple inputs to uncommon calls, so they can be scheduled late | |
2218 // and not commoned up and forced early. Must come after regular | |
2219 // optimizations to avoid GVN undoing the cloning. Clone constant | |
2220 // inputs to Loop Phis; these will be split by the allocator anyways. | |
2221 // Remove Opaque nodes. | |
2222 // (2) Move last-uses by commutative operations to the left input to encourage | |
2223 // Intel update-in-place two-address operations and better register usage | |
2224 // on RISCs. Must come after regular optimizations to avoid GVN Ideal | |
2225 // calls canonicalizing them back. | |
2226 // (3) Count the number of double-precision FP ops, single-precision FP ops | |
2227 // and call sites. On Intel, we can get correct rounding either by | |
2228 // forcing singles to memory (requires extra stores and loads after each | |
2229 // FP bytecode) or we can set a rounding mode bit (requires setting and | |
2230 // clearing the mode bit around call sites). The mode bit is only used | |
2231 // if the relative frequency of single FP ops to calls is low enough. | |
2232 // This is a key transform for SPEC mpeg_audio. | |
2233 // (4) Detect infinite loops; blobs of code reachable from above but not | |
2234 // below. Several of the Code_Gen algorithms fail on such code shapes, | |
2235 // so we simply bail out. Happens a lot in ZKM.jar, but also happens | |
2236 // from time to time in other codes (such as -Xcomp finalizer loops, etc). | |
2237 // Detection is by looking for IfNodes where only 1 projection is | |
2238 // reachable from below or CatchNodes missing some targets. | |
2239 // (5) Assert for insane oop offsets in debug mode. | |
2240 | |
2241 bool Compile::final_graph_reshaping() { | |
2242 // an infinite loop may have been eliminated by the optimizer, | |
2243 // in which case the graph will be empty. | |
2244 if (root()->req() == 1) { | |
2245 record_method_not_compilable("trivial infinite loop"); | |
2246 return true; | |
2247 } | |
2248 | |
2249 Final_Reshape_Counts fpu; | |
2250 | |
2251 // Visit everybody reachable! | |
2252 // Allocate stack of size C->unique()/2 to avoid frequent realloc | |
2253 Node_Stack nstack(unique() >> 1); | |
2254 final_graph_reshaping_walk(nstack, root(), fpu); | |
2255 | |
2256 // Check for unreachable (from below) code (i.e., infinite loops). | |
2257 for( uint i = 0; i < fpu._tests.size(); i++ ) { | |
127 | 2258 MultiBranchNode *n = fpu._tests[i]->as_MultiBranch(); |
2259 // Get number of CFG targets. | |
0 | 2260 // Note that PCTables include exception targets after calls. |
127 | 2261 uint required_outcnt = n->required_outcnt(); |
2262 if (n->outcnt() != required_outcnt) { | |
0 | 2263 // Check for a few special cases. Rethrow Nodes never take the |
2264 // 'fall-thru' path, so expected kids is 1 less. | |
2265 if (n->is_PCTable() && n->in(0) && n->in(0)->in(0)) { | |
2266 if (n->in(0)->in(0)->is_Call()) { | |
2267 CallNode *call = n->in(0)->in(0)->as_Call(); | |
2268 if (call->entry_point() == OptoRuntime::rethrow_stub()) { | |
127 | 2269 required_outcnt--; // Rethrow always has 1 less kid |
0 | 2270 } else if (call->req() > TypeFunc::Parms && |
2271 call->is_CallDynamicJava()) { | |
2272 // Check for null receiver. In such case, the optimizer has | |
2273 // detected that the virtual call will always result in a null | |
2274 // pointer exception. The fall-through projection of this CatchNode | |
2275 // will not be populated. | |
2276 Node *arg0 = call->in(TypeFunc::Parms); | |
2277 if (arg0->is_Type() && | |
2278 arg0->as_Type()->type()->higher_equal(TypePtr::NULL_PTR)) { | |
127 | 2279 required_outcnt--; |
0 | 2280 } |
2281 } else if (call->entry_point() == OptoRuntime::new_array_Java() && | |
2282 call->req() > TypeFunc::Parms+1 && | |
2283 call->is_CallStaticJava()) { | |
2284 // Check for negative array length. In such case, the optimizer has | |
2285 // detected that the allocation attempt will always result in an | |
2286 // exception. There is no fall-through projection of this CatchNode . | |
2287 Node *arg1 = call->in(TypeFunc::Parms+1); | |
2288 if (arg1->is_Type() && | |
2289 arg1->as_Type()->type()->join(TypeInt::POS)->empty()) { | |
127 | 2290 required_outcnt--; |
0 | 2291 } |
2292 } | |
2293 } | |
2294 } | |
127 | 2295 // Recheck with a better notion of 'required_outcnt' |
2296 if (n->outcnt() != required_outcnt) { | |
0 | 2297 record_method_not_compilable("malformed control flow"); |
2298 return true; // Not all targets reachable! | |
2299 } | |
2300 } | |
2301 // Check that I actually visited all kids. Unreached kids | |
2302 // must be infinite loops. | |
2303 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) | |
2304 if (!fpu._visited.test(n->fast_out(j)->_idx)) { | |
2305 record_method_not_compilable("infinite loop"); | |
2306 return true; // Found unvisited kid; must be unreach | |
2307 } | |
2308 } | |
2309 | |
2310 // If original bytecodes contained a mixture of floats and doubles | |
2311 // check if the optimizer has made it homogenous, item (3). | |
2312 if( Use24BitFPMode && Use24BitFP && | |
2313 fpu.get_float_count() > 32 && | |
2314 fpu.get_double_count() == 0 && | |
2315 (10 * fpu.get_call_count() < fpu.get_float_count()) ) { | |
2316 set_24_bit_selection_and_mode( false, true ); | |
2317 } | |
2318 | |
2319 set_has_java_calls(fpu.get_java_call_count() > 0); | |
2320 | |
2321 // No infinite loops, no reason to bail out. | |
2322 return false; | |
2323 } | |
2324 | |
2325 //-----------------------------too_many_traps---------------------------------- | |
2326 // Report if there are too many traps at the current method and bci. | |
2327 // Return true if there was a trap, and/or PerMethodTrapLimit is exceeded. | |
2328 bool Compile::too_many_traps(ciMethod* method, | |
2329 int bci, | |
2330 Deoptimization::DeoptReason reason) { | |
2331 ciMethodData* md = method->method_data(); | |
2332 if (md->is_empty()) { | |
2333 // Assume the trap has not occurred, or that it occurred only | |
2334 // because of a transient condition during start-up in the interpreter. | |
2335 return false; | |
2336 } | |
2337 if (md->has_trap_at(bci, reason) != 0) { | |
2338 // Assume PerBytecodeTrapLimit==0, for a more conservative heuristic. | |
2339 // Also, if there are multiple reasons, or if there is no per-BCI record, | |
2340 // assume the worst. | |
2341 if (log()) | |
2342 log()->elem("observe trap='%s' count='%d'", | |
2343 Deoptimization::trap_reason_name(reason), | |
2344 md->trap_count(reason)); | |
2345 return true; | |
2346 } else { | |
2347 // Ignore method/bci and see if there have been too many globally. | |
2348 return too_many_traps(reason, md); | |
2349 } | |
2350 } | |
2351 | |
2352 // Less-accurate variant which does not require a method and bci. | |
2353 bool Compile::too_many_traps(Deoptimization::DeoptReason reason, | |
2354 ciMethodData* logmd) { | |
2355 if (trap_count(reason) >= (uint)PerMethodTrapLimit) { | |
2356 // Too many traps globally. | |
2357 // Note that we use cumulative trap_count, not just md->trap_count. | |
2358 if (log()) { | |
2359 int mcount = (logmd == NULL)? -1: (int)logmd->trap_count(reason); | |
2360 log()->elem("observe trap='%s' count='0' mcount='%d' ccount='%d'", | |
2361 Deoptimization::trap_reason_name(reason), | |
2362 mcount, trap_count(reason)); | |
2363 } | |
2364 return true; | |
2365 } else { | |
2366 // The coast is clear. | |
2367 return false; | |
2368 } | |
2369 } | |
2370 | |
2371 //--------------------------too_many_recompiles-------------------------------- | |
2372 // Report if there are too many recompiles at the current method and bci. | |
2373 // Consults PerBytecodeRecompilationCutoff and PerMethodRecompilationCutoff. | |
2374 // Is not eager to return true, since this will cause the compiler to use | |
2375 // Action_none for a trap point, to avoid too many recompilations. | |
2376 bool Compile::too_many_recompiles(ciMethod* method, | |
2377 int bci, | |
2378 Deoptimization::DeoptReason reason) { | |
2379 ciMethodData* md = method->method_data(); | |
2380 if (md->is_empty()) { | |
2381 // Assume the trap has not occurred, or that it occurred only | |
2382 // because of a transient condition during start-up in the interpreter. | |
2383 return false; | |
2384 } | |
2385 // Pick a cutoff point well within PerBytecodeRecompilationCutoff. | |
2386 uint bc_cutoff = (uint) PerBytecodeRecompilationCutoff / 8; | |
2387 uint m_cutoff = (uint) PerMethodRecompilationCutoff / 2 + 1; // not zero | |
2388 Deoptimization::DeoptReason per_bc_reason | |
2389 = Deoptimization::reason_recorded_per_bytecode_if_any(reason); | |
2390 if ((per_bc_reason == Deoptimization::Reason_none | |
2391 || md->has_trap_at(bci, reason) != 0) | |
2392 // The trap frequency measure we care about is the recompile count: | |
2393 && md->trap_recompiled_at(bci) | |
2394 && md->overflow_recompile_count() >= bc_cutoff) { | |
2395 // Do not emit a trap here if it has already caused recompilations. | |
2396 // Also, if there are multiple reasons, or if there is no per-BCI record, | |
2397 // assume the worst. | |
2398 if (log()) | |
2399 log()->elem("observe trap='%s recompiled' count='%d' recompiles2='%d'", | |
2400 Deoptimization::trap_reason_name(reason), | |
2401 md->trap_count(reason), | |
2402 md->overflow_recompile_count()); | |
2403 return true; | |
2404 } else if (trap_count(reason) != 0 | |
2405 && decompile_count() >= m_cutoff) { | |
2406 // Too many recompiles globally, and we have seen this sort of trap. | |
2407 // Use cumulative decompile_count, not just md->decompile_count. | |
2408 if (log()) | |
2409 log()->elem("observe trap='%s' count='%d' mcount='%d' decompiles='%d' mdecompiles='%d'", | |
2410 Deoptimization::trap_reason_name(reason), | |
2411 md->trap_count(reason), trap_count(reason), | |
2412 md->decompile_count(), decompile_count()); | |
2413 return true; | |
2414 } else { | |
2415 // The coast is clear. | |
2416 return false; | |
2417 } | |
2418 } | |
2419 | |
2420 | |
2421 #ifndef PRODUCT | |
2422 //------------------------------verify_graph_edges--------------------------- | |
2423 // Walk the Graph and verify that there is a one-to-one correspondence | |
2424 // between Use-Def edges and Def-Use edges in the graph. | |
2425 void Compile::verify_graph_edges(bool no_dead_code) { | |
2426 if (VerifyGraphEdges) { | |
2427 ResourceArea *area = Thread::current()->resource_area(); | |
2428 Unique_Node_List visited(area); | |
2429 // Call recursive graph walk to check edges | |
2430 _root->verify_edges(visited); | |
2431 if (no_dead_code) { | |
2432 // Now make sure that no visited node is used by an unvisited node. | |
2433 bool dead_nodes = 0; | |
2434 Unique_Node_List checked(area); | |
2435 while (visited.size() > 0) { | |
2436 Node* n = visited.pop(); | |
2437 checked.push(n); | |
2438 for (uint i = 0; i < n->outcnt(); i++) { | |
2439 Node* use = n->raw_out(i); | |
2440 if (checked.member(use)) continue; // already checked | |
2441 if (visited.member(use)) continue; // already in the graph | |
2442 if (use->is_Con()) continue; // a dead ConNode is OK | |
2443 // At this point, we have found a dead node which is DU-reachable. | |
2444 if (dead_nodes++ == 0) | |
2445 tty->print_cr("*** Dead nodes reachable via DU edges:"); | |
2446 use->dump(2); | |
2447 tty->print_cr("---"); | |
2448 checked.push(use); // No repeats; pretend it is now checked. | |
2449 } | |
2450 } | |
2451 assert(dead_nodes == 0, "using nodes must be reachable from root"); | |
2452 } | |
2453 } | |
2454 } | |
2455 #endif | |
2456 | |
2457 // The Compile object keeps track of failure reasons separately from the ciEnv. | |
2458 // This is required because there is not quite a 1-1 relation between the | |
2459 // ciEnv and its compilation task and the Compile object. Note that one | |
2460 // ciEnv might use two Compile objects, if C2Compiler::compile_method decides | |
2461 // to backtrack and retry without subsuming loads. Other than this backtracking | |
2462 // behavior, the Compile's failure reason is quietly copied up to the ciEnv | |
2463 // by the logic in C2Compiler. | |
2464 void Compile::record_failure(const char* reason) { | |
2465 if (log() != NULL) { | |
2466 log()->elem("failure reason='%s' phase='compile'", reason); | |
2467 } | |
2468 if (_failure_reason == NULL) { | |
2469 // Record the first failure reason. | |
2470 _failure_reason = reason; | |
2471 } | |
222 | 2472 if (!C->failure_reason_is(C2Compiler::retry_no_subsuming_loads())) { |
2473 C->print_method(_failure_reason); | |
2474 } | |
0 | 2475 _root = NULL; // flush the graph, too |
2476 } | |
2477 | |
2478 Compile::TracePhase::TracePhase(const char* name, elapsedTimer* accumulator, bool dolog) | |
2479 : TraceTime(NULL, accumulator, false NOT_PRODUCT( || TimeCompiler ), false) | |
2480 { | |
2481 if (dolog) { | |
2482 C = Compile::current(); | |
2483 _log = C->log(); | |
2484 } else { | |
2485 C = NULL; | |
2486 _log = NULL; | |
2487 } | |
2488 if (_log != NULL) { | |
2489 _log->begin_head("phase name='%s' nodes='%d'", name, C->unique()); | |
2490 _log->stamp(); | |
2491 _log->end_head(); | |
2492 } | |
2493 } | |
2494 | |
2495 Compile::TracePhase::~TracePhase() { | |
2496 if (_log != NULL) { | |
2497 _log->done("phase nodes='%d'", C->unique()); | |
2498 } | |
2499 } |