Bug Summary

File:jdk/src/hotspot/share/opto/compile.cpp
Warning:line 2150, column 23
Value stored to 'save_for_igvn' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name compile.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/libjvm/objs/precompiled -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D _GNU_SOURCE -D _REENTRANT -D LIBC=gnu -D LINUX -D VM_LITTLE_ENDIAN -D _LP64=1 -D ASSERT -D CHECK_UNHANDLED_OOPS -D TARGET_ARCH_x86 -D INCLUDE_SUFFIX_OS=_linux -D INCLUDE_SUFFIX_CPU=_x86 -D INCLUDE_SUFFIX_COMPILER=_gcc -D TARGET_COMPILER_gcc -D AMD64 -D HOTSPOT_LIB_ARCH="amd64" -D COMPILER1 -D COMPILER2 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc/adfiles -I /home/daniel/Projects/java/jdk/src/hotspot/share -I /home/daniel/Projects/java/jdk/src/hotspot/os/linux -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix -I /home/daniel/Projects/java/jdk/src/hotspot/cpu/x86 -I /home/daniel/Projects/java/jdk/src/hotspot/os_cpu/linux_x86 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc -I /home/daniel/Projects/java/jdk/src/hotspot/share/precompiled -I /home/daniel/Projects/java/jdk/src/hotspot/share/include -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix/include -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base/linux -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libjimage -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc/adfiles -I /home/daniel/Projects/java/jdk/src/hotspot/share -I /home/daniel/Projects/java/jdk/src/hotspot/os/linux -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix -I /home/daniel/Projects/java/jdk/src/hotspot/cpu/x86 -I /home/daniel/Projects/java/jdk/src/hotspot/os_cpu/linux_x86 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/hotspot/variant-server/gensrc -D _FORTIFY_SOURCE=2 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-format-zero-length -Wno-unused-parameter -Wno-unused -Wno-parentheses -Wno-comment -Wno-unknown-pragmas -Wno-address -Wno-delete-non-virtual-dtor -Wno-char-subscripts -Wno-array-bounds -Wno-int-in-bool-context -Wno-ignored-qualifiers -Wno-missing-field-initializers -Wno-implicit-fallthrough -Wno-empty-body -Wno-strict-overflow -Wno-sequence-point -Wno-maybe-uninitialized -Wno-misleading-indentation -Wno-cast-function-type -Wno-shift-negative-value -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /home/daniel/Projects/java/jdk/make/hotspot -ferror-limit 19 -fmessage-length 0 -fvisibility hidden -stack-protector 1 -fno-rtti -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /home/daniel/Projects/java/scan/2021-12-21-193737-8510-1 -x c++ /home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp
1/*
2 * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25#include "precompiled.hpp"
26#include "jvm_io.h"
27#include "asm/macroAssembler.hpp"
28#include "asm/macroAssembler.inline.hpp"
29#include "ci/ciReplay.hpp"
30#include "classfile/javaClasses.hpp"
31#include "code/exceptionHandlerTable.hpp"
32#include "code/nmethod.hpp"
33#include "compiler/compileBroker.hpp"
34#include "compiler/compileLog.hpp"
35#include "compiler/disassembler.hpp"
36#include "compiler/oopMap.hpp"
37#include "gc/shared/barrierSet.hpp"
38#include "gc/shared/c2/barrierSetC2.hpp"
39#include "jfr/jfrEvents.hpp"
40#include "memory/resourceArea.hpp"
41#include "opto/addnode.hpp"
42#include "opto/block.hpp"
43#include "opto/c2compiler.hpp"
44#include "opto/callGenerator.hpp"
45#include "opto/callnode.hpp"
46#include "opto/castnode.hpp"
47#include "opto/cfgnode.hpp"
48#include "opto/chaitin.hpp"
49#include "opto/compile.hpp"
50#include "opto/connode.hpp"
51#include "opto/convertnode.hpp"
52#include "opto/divnode.hpp"
53#include "opto/escape.hpp"
54#include "opto/idealGraphPrinter.hpp"
55#include "opto/loopnode.hpp"
56#include "opto/machnode.hpp"
57#include "opto/macro.hpp"
58#include "opto/matcher.hpp"
59#include "opto/mathexactnode.hpp"
60#include "opto/memnode.hpp"
61#include "opto/mulnode.hpp"
62#include "opto/narrowptrnode.hpp"
63#include "opto/node.hpp"
64#include "opto/opcodes.hpp"
65#include "opto/output.hpp"
66#include "opto/parse.hpp"
67#include "opto/phaseX.hpp"
68#include "opto/rootnode.hpp"
69#include "opto/runtime.hpp"
70#include "opto/stringopts.hpp"
71#include "opto/type.hpp"
72#include "opto/vector.hpp"
73#include "opto/vectornode.hpp"
74#include "runtime/globals_extension.hpp"
75#include "runtime/sharedRuntime.hpp"
76#include "runtime/signature.hpp"
77#include "runtime/stubRoutines.hpp"
78#include "runtime/timer.hpp"
79#include "utilities/align.hpp"
80#include "utilities/copy.hpp"
81#include "utilities/macros.hpp"
82#include "utilities/resourceHash.hpp"
83
84
85// -------------------- Compile::mach_constant_base_node -----------------------
86// Constant table base node singleton.
87MachConstantBaseNode* Compile::mach_constant_base_node() {
88 if (_mach_constant_base_node == NULL__null) {
89 _mach_constant_base_node = new MachConstantBaseNode();
90 _mach_constant_base_node->add_req(C->root());
91 }
92 return _mach_constant_base_node;
93}
94
95
96/// Support for intrinsics.
97
98// Return the index at which m must be inserted (or already exists).
99// The sort order is by the address of the ciMethod, with is_virtual as minor key.
100class IntrinsicDescPair {
101 private:
102 ciMethod* _m;
103 bool _is_virtual;
104 public:
105 IntrinsicDescPair(ciMethod* m, bool is_virtual) : _m(m), _is_virtual(is_virtual) {}
106 static int compare(IntrinsicDescPair* const& key, CallGenerator* const& elt) {
107 ciMethod* m= elt->method();
108 ciMethod* key_m = key->_m;
109 if (key_m < m) return -1;
110 else if (key_m > m) return 1;
111 else {
112 bool is_virtual = elt->is_virtual();
113 bool key_virtual = key->_is_virtual;
114 if (key_virtual < is_virtual) return -1;
115 else if (key_virtual > is_virtual) return 1;
116 else return 0;
117 }
118 }
119};
120int Compile::intrinsic_insertion_index(ciMethod* m, bool is_virtual, bool& found) {
121#ifdef ASSERT1
122 for (int i = 1; i < _intrinsics.length(); i++) {
123 CallGenerator* cg1 = _intrinsics.at(i-1);
124 CallGenerator* cg2 = _intrinsics.at(i);
125 assert(cg1->method() != cg2->method()do { if (!(cg1->method() != cg2->method() ? cg1->method
() < cg2->method() : cg1->is_virtual() < cg2->
is_virtual())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 128, "assert(" "cg1->method() != cg2->method() ? cg1->method() < cg2->method() : cg1->is_virtual() < cg2->is_virtual()"
") failed", "compiler intrinsics list must stay sorted"); ::
breakpoint(); } } while (0)
126 ? cg1->method() < cg2->method()do { if (!(cg1->method() != cg2->method() ? cg1->method
() < cg2->method() : cg1->is_virtual() < cg2->
is_virtual())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 128, "assert(" "cg1->method() != cg2->method() ? cg1->method() < cg2->method() : cg1->is_virtual() < cg2->is_virtual()"
") failed", "compiler intrinsics list must stay sorted"); ::
breakpoint(); } } while (0)
127 : cg1->is_virtual() < cg2->is_virtual(),do { if (!(cg1->method() != cg2->method() ? cg1->method
() < cg2->method() : cg1->is_virtual() < cg2->
is_virtual())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 128, "assert(" "cg1->method() != cg2->method() ? cg1->method() < cg2->method() : cg1->is_virtual() < cg2->is_virtual()"
") failed", "compiler intrinsics list must stay sorted"); ::
breakpoint(); } } while (0)
128 "compiler intrinsics list must stay sorted")do { if (!(cg1->method() != cg2->method() ? cg1->method
() < cg2->method() : cg1->is_virtual() < cg2->
is_virtual())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 128, "assert(" "cg1->method() != cg2->method() ? cg1->method() < cg2->method() : cg1->is_virtual() < cg2->is_virtual()"
") failed", "compiler intrinsics list must stay sorted"); ::
breakpoint(); } } while (0)
;
129 }
130#endif
131 IntrinsicDescPair pair(m, is_virtual);
132 return _intrinsics.find_sorted<IntrinsicDescPair*, IntrinsicDescPair::compare>(&pair, found);
133}
134
135void Compile::register_intrinsic(CallGenerator* cg) {
136 bool found = false;
137 int index = intrinsic_insertion_index(cg->method(), cg->is_virtual(), found);
138 assert(!found, "registering twice")do { if (!(!found)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 138, "assert(" "!found" ") failed", "registering twice"); ::
breakpoint(); } } while (0)
;
139 _intrinsics.insert_before(index, cg);
140 assert(find_intrinsic(cg->method(), cg->is_virtual()) == cg, "registration worked")do { if (!(find_intrinsic(cg->method(), cg->is_virtual(
)) == cg)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 140, "assert(" "find_intrinsic(cg->method(), cg->is_virtual()) == cg"
") failed", "registration worked"); ::breakpoint(); } } while
(0)
;
141}
142
143CallGenerator* Compile::find_intrinsic(ciMethod* m, bool is_virtual) {
144 assert(m->is_loaded(), "don't try this on unloaded methods")do { if (!(m->is_loaded())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 144, "assert(" "m->is_loaded()" ") failed", "don't try this on unloaded methods"
); ::breakpoint(); } } while (0)
;
145 if (_intrinsics.length() > 0) {
146 bool found = false;
147 int index = intrinsic_insertion_index(m, is_virtual, found);
148 if (found) {
149 return _intrinsics.at(index);
150 }
151 }
152 // Lazily create intrinsics for intrinsic IDs well-known in the runtime.
153 if (m->intrinsic_id() != vmIntrinsics::_none &&
154 m->intrinsic_id() <= vmIntrinsics::LAST_COMPILER_INLINE) {
155 CallGenerator* cg = make_vm_intrinsic(m, is_virtual);
156 if (cg != NULL__null) {
157 // Save it for next time:
158 register_intrinsic(cg);
159 return cg;
160 } else {
161 gather_intrinsic_statistics(m->intrinsic_id(), is_virtual, _intrinsic_disabled);
162 }
163 }
164 return NULL__null;
165}
166
167// Compile::make_vm_intrinsic is defined in library_call.cpp.
168
169#ifndef PRODUCT
170// statistics gathering...
171
172juint Compile::_intrinsic_hist_count[vmIntrinsics::number_of_intrinsics()] = {0};
173jubyte Compile::_intrinsic_hist_flags[vmIntrinsics::number_of_intrinsics()] = {0};
174
175inline int as_int(vmIntrinsics::ID id) {
176 return vmIntrinsics::as_int(id);
177}
178
179bool Compile::gather_intrinsic_statistics(vmIntrinsics::ID id, bool is_virtual, int flags) {
180 assert(id > vmIntrinsics::_none && id < vmIntrinsics::ID_LIMIT, "oob")do { if (!(id > vmIntrinsics::_none && id < vmIntrinsics
::ID_LIMIT)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 180, "assert(" "id > vmIntrinsics::_none && id < vmIntrinsics::ID_LIMIT"
") failed", "oob"); ::breakpoint(); } } while (0)
;
181 int oflags = _intrinsic_hist_flags[as_int(id)];
182 assert(flags != 0, "what happened?")do { if (!(flags != 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 182, "assert(" "flags != 0" ") failed", "what happened?"); ::
breakpoint(); } } while (0)
;
183 if (is_virtual) {
184 flags |= _intrinsic_virtual;
185 }
186 bool changed = (flags != oflags);
187 if ((flags & _intrinsic_worked) != 0) {
188 juint count = (_intrinsic_hist_count[as_int(id)] += 1);
189 if (count == 1) {
190 changed = true; // first time
191 }
192 // increment the overall count also:
193 _intrinsic_hist_count[as_int(vmIntrinsics::_none)] += 1;
194 }
195 if (changed) {
196 if (((oflags ^ flags) & _intrinsic_virtual) != 0) {
197 // Something changed about the intrinsic's virtuality.
198 if ((flags & _intrinsic_virtual) != 0) {
199 // This is the first use of this intrinsic as a virtual call.
200 if (oflags != 0) {
201 // We already saw it as a non-virtual, so note both cases.
202 flags |= _intrinsic_both;
203 }
204 } else if ((oflags & _intrinsic_both) == 0) {
205 // This is the first use of this intrinsic as a non-virtual
206 flags |= _intrinsic_both;
207 }
208 }
209 _intrinsic_hist_flags[as_int(id)] = (jubyte) (oflags | flags);
210 }
211 // update the overall flags also:
212 _intrinsic_hist_flags[as_int(vmIntrinsics::_none)] |= (jubyte) flags;
213 return changed;
214}
215
216static char* format_flags(int flags, char* buf) {
217 buf[0] = 0;
218 if ((flags & Compile::_intrinsic_worked) != 0) strcat(buf, ",worked");
219 if ((flags & Compile::_intrinsic_failed) != 0) strcat(buf, ",failed");
220 if ((flags & Compile::_intrinsic_disabled) != 0) strcat(buf, ",disabled");
221 if ((flags & Compile::_intrinsic_virtual) != 0) strcat(buf, ",virtual");
222 if ((flags & Compile::_intrinsic_both) != 0) strcat(buf, ",nonvirtual");
223 if (buf[0] == 0) strcat(buf, ",");
224 assert(buf[0] == ',', "must be")do { if (!(buf[0] == ',')) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 224, "assert(" "buf[0] == ','" ") failed", "must be"); ::breakpoint
(); } } while (0)
;
225 return &buf[1];
226}
227
228void Compile::print_intrinsic_statistics() {
229 char flagsbuf[100];
230 ttyLocker ttyl;
231 if (xtty != NULL__null) xtty->head("statistics type='intrinsic'");
232 tty->print_cr("Compiler intrinsic usage:");
233 juint total = _intrinsic_hist_count[as_int(vmIntrinsics::_none)];
234 if (total == 0) total = 1; // avoid div0 in case of no successes
235 #define PRINT_STAT_LINE(name, c, f)tty->print_cr(" %4d (%4.1f%%) %s (%s)", (int)(c), ((c) * 100.0
) / total, name, f);
\
236 tty->print_cr(" %4d (%4.1f%%) %s (%s)", (int)(c), ((c) * 100.0) / total, name, f);
237 for (auto id : EnumRange<vmIntrinsicID>{}) {
238 int flags = _intrinsic_hist_flags[as_int(id)];
239 juint count = _intrinsic_hist_count[as_int(id)];
240 if ((flags | count) != 0) {
241 PRINT_STAT_LINE(vmIntrinsics::name_at(id), count, format_flags(flags, flagsbuf))tty->print_cr(" %4d (%4.1f%%) %s (%s)", (int)(count), ((count
) * 100.0) / total, vmIntrinsics::name_at(id), format_flags(flags
, flagsbuf));
;
242 }
243 }
244 PRINT_STAT_LINE("total", total, format_flags(_intrinsic_hist_flags[as_int(vmIntrinsics::_none)], flagsbuf))tty->print_cr(" %4d (%4.1f%%) %s (%s)", (int)(total), ((total
) * 100.0) / total, "total", format_flags(_intrinsic_hist_flags
[as_int(vmIntrinsics::_none)], flagsbuf));
;
245 if (xtty != NULL__null) xtty->tail("statistics");
246}
247
248void Compile::print_statistics() {
249 { ttyLocker ttyl;
250 if (xtty != NULL__null) xtty->head("statistics type='opto'");
251 Parse::print_statistics();
252 PhaseCCP::print_statistics();
253 PhaseRegAlloc::print_statistics();
254 PhaseOutput::print_statistics();
255 PhasePeephole::print_statistics();
256 PhaseIdealLoop::print_statistics();
257 if (xtty != NULL__null) xtty->tail("statistics");
258 }
259 if (_intrinsic_hist_flags[as_int(vmIntrinsics::_none)] != 0) {
260 // put this under its own <statistics> element.
261 print_intrinsic_statistics();
262 }
263}
264#endif //PRODUCT
265
266void Compile::gvn_replace_by(Node* n, Node* nn) {
267 for (DUIterator_Last imin, i = n->last_outs(imin); i >= imin; ) {
268 Node* use = n->last_out(i);
269 bool is_in_table = initial_gvn()->hash_delete(use);
270 uint uses_found = 0;
271 for (uint j = 0; j < use->len(); j++) {
272 if (use->in(j) == n) {
273 if (j < use->req())
274 use->set_req(j, nn);
275 else
276 use->set_prec(j, nn);
277 uses_found++;
278 }
279 }
280 if (is_in_table) {
281 // reinsert into table
282 initial_gvn()->hash_find_insert(use);
283 }
284 record_for_igvn(use);
285 i -= uses_found; // we deleted 1 or more copies of this edge
286 }
287}
288
289
290// Identify all nodes that are reachable from below, useful.
291// Use breadth-first pass that records state in a Unique_Node_List,
292// recursive traversal is slower.
293void Compile::identify_useful_nodes(Unique_Node_List &useful) {
294 int estimated_worklist_size = live_nodes();
295 useful.map( estimated_worklist_size, NULL__null ); // preallocate space
296
297 // Initialize worklist
298 if (root() != NULL__null) { useful.push(root()); }
299 // If 'top' is cached, declare it useful to preserve cached node
300 if( cached_top_node() ) { useful.push(cached_top_node()); }
301
302 // Push all useful nodes onto the list, breadthfirst
303 for( uint next = 0; next < useful.size(); ++next ) {
304 assert( next < unique(), "Unique useful nodes < total nodes")do { if (!(next < unique())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 304, "assert(" "next < unique()" ") failed", "Unique useful nodes < total nodes"
); ::breakpoint(); } } while (0)
;
305 Node *n = useful.at(next);
306 uint max = n->len();
307 for( uint i = 0; i < max; ++i ) {
308 Node *m = n->in(i);
309 if (not_a_node(m)) continue;
310 useful.push(m);
311 }
312 }
313}
314
315// Update dead_node_list with any missing dead nodes using useful
316// list. Consider all non-useful nodes to be useless i.e., dead nodes.
317void Compile::update_dead_node_list(Unique_Node_List &useful) {
318 uint max_idx = unique();
319 VectorSet& useful_node_set = useful.member_set();
320
321 for (uint node_idx = 0; node_idx < max_idx; node_idx++) {
322 // If node with index node_idx is not in useful set,
323 // mark it as dead in dead node list.
324 if (!useful_node_set.test(node_idx)) {
325 record_dead_node(node_idx);
326 }
327 }
328}
329
330void Compile::remove_useless_late_inlines(GrowableArray<CallGenerator*>* inlines, Unique_Node_List &useful) {
331 int shift = 0;
332 for (int i = 0; i < inlines->length(); i++) {
333 CallGenerator* cg = inlines->at(i);
334 if (useful.member(cg->call_node())) {
335 if (shift > 0) {
336 inlines->at_put(i - shift, cg);
337 }
338 } else {
339 shift++; // skip over the dead element
340 }
341 }
342 if (shift > 0) {
343 inlines->trunc_to(inlines->length() - shift); // remove last elements from compacted array
344 }
345}
346
347void Compile::remove_useless_late_inlines(GrowableArray<CallGenerator*>* inlines, Node* dead) {
348 assert(dead != NULL && dead->is_Call(), "sanity")do { if (!(dead != __null && dead->is_Call())) { (
*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 348, "assert(" "dead != __null && dead->is_Call()"
") failed", "sanity"); ::breakpoint(); } } while (0)
;
349 int found = 0;
350 for (int i = 0; i < inlines->length(); i++) {
351 if (inlines->at(i)->call_node() == dead) {
352 inlines->remove_at(i);
353 found++;
354 NOT_DEBUG( break; ) // elements are unique, so exit early
355 }
356 }
357 assert(found <= 1, "not unique")do { if (!(found <= 1)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 357, "assert(" "found <= 1" ") failed", "not unique"); ::
breakpoint(); } } while (0)
;
358}
359
360void Compile::remove_useless_nodes(GrowableArray<Node*>& node_list, Unique_Node_List& useful) {
361 for (int i = node_list.length() - 1; i >= 0; i--) {
362 Node* n = node_list.at(i);
363 if (!useful.member(n)) {
364 node_list.delete_at(i); // replaces i-th with last element which is known to be useful (already processed)
365 }
366 }
367}
368
369void Compile::remove_useless_node(Node* dead) {
370 remove_modified_node(dead);
371
372 // Constant node that has no out-edges and has only one in-edge from
373 // root is usually dead. However, sometimes reshaping walk makes
374 // it reachable by adding use edges. So, we will NOT count Con nodes
375 // as dead to be conservative about the dead node count at any
376 // given time.
377 if (!dead->is_Con()) {
378 record_dead_node(dead->_idx);
379 }
380 if (dead->is_macro()) {
381 remove_macro_node(dead);
382 }
383 if (dead->is_expensive()) {
384 remove_expensive_node(dead);
385 }
386 if (dead->Opcode() == Op_Opaque4) {
387 remove_skeleton_predicate_opaq(dead);
388 }
389 if (dead->for_post_loop_opts_igvn()) {
390 remove_from_post_loop_opts_igvn(dead);
391 }
392 if (dead->is_Call()) {
393 remove_useless_late_inlines( &_late_inlines, dead);
394 remove_useless_late_inlines( &_string_late_inlines, dead);
395 remove_useless_late_inlines( &_boxing_late_inlines, dead);
396 remove_useless_late_inlines(&_vector_reboxing_late_inlines, dead);
397 }
398 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
399 bs->unregister_potential_barrier_node(dead);
400}
401
402// Disconnect all useless nodes by disconnecting those at the boundary.
403void Compile::remove_useless_nodes(Unique_Node_List &useful) {
404 uint next = 0;
405 while (next < useful.size()) {
406 Node *n = useful.at(next++);
407 if (n->is_SafePoint()) {
408 // We're done with a parsing phase. Replaced nodes are not valid
409 // beyond that point.
410 n->as_SafePoint()->delete_replaced_nodes();
411 }
412 // Use raw traversal of out edges since this code removes out edges
413 int max = n->outcnt();
414 for (int j = 0; j < max; ++j) {
415 Node* child = n->raw_out(j);
416 if (!useful.member(child)) {
417 assert(!child->is_top() || child != top(),do { if (!(!child->is_top() || child != top())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 418, "assert(" "!child->is_top() || child != top()" ") failed"
, "If top is cached in Compile object it is in useful list");
::breakpoint(); } } while (0)
418 "If top is cached in Compile object it is in useful list")do { if (!(!child->is_top() || child != top())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 418, "assert(" "!child->is_top() || child != top()" ") failed"
, "If top is cached in Compile object it is in useful list");
::breakpoint(); } } while (0)
;
419 // Only need to remove this out-edge to the useless node
420 n->raw_del_out(j);
421 --j;
422 --max;
423 }
424 }
425 if (n->outcnt() == 1 && n->has_special_unique_user()) {
426 record_for_igvn(n->unique_out());
427 }
428 }
429
430 remove_useless_nodes(_macro_nodes, useful); // remove useless macro nodes
431 remove_useless_nodes(_predicate_opaqs, useful); // remove useless predicate opaque nodes
432 remove_useless_nodes(_skeleton_predicate_opaqs, useful);
433 remove_useless_nodes(_expensive_nodes, useful); // remove useless expensive nodes
434 remove_useless_nodes(_for_post_loop_igvn, useful); // remove useless node recorded for post loop opts IGVN pass
435 remove_useless_coarsened_locks(useful); // remove useless coarsened locks nodes
436
437 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
438 bs->eliminate_useless_gc_barriers(useful, this);
439 // clean up the late inline lists
440 remove_useless_late_inlines( &_late_inlines, useful);
441 remove_useless_late_inlines( &_string_late_inlines, useful);
442 remove_useless_late_inlines( &_boxing_late_inlines, useful);
443 remove_useless_late_inlines(&_vector_reboxing_late_inlines, useful);
444 debug_only(verify_graph_edges(true/*check for no_dead_code*/);)verify_graph_edges(true );
445}
446
447// ============================================================================
448//------------------------------CompileWrapper---------------------------------
449class CompileWrapper : public StackObj {
450 Compile *const _compile;
451 public:
452 CompileWrapper(Compile* compile);
453
454 ~CompileWrapper();
455};
456
457CompileWrapper::CompileWrapper(Compile* compile) : _compile(compile) {
458 // the Compile* pointer is stored in the current ciEnv:
459 ciEnv* env = compile->env();
460 assert(env == ciEnv::current(), "must already be a ciEnv active")do { if (!(env == ciEnv::current())) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 460, "assert(" "env == ciEnv::current()" ") failed", "must already be a ciEnv active"
); ::breakpoint(); } } while (0)
;
461 assert(env->compiler_data() == NULL, "compile already active?")do { if (!(env->compiler_data() == __null)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 461, "assert(" "env->compiler_data() == __null" ") failed"
, "compile already active?"); ::breakpoint(); } } while (0)
;
462 env->set_compiler_data(compile);
463 assert(compile == Compile::current(), "sanity")do { if (!(compile == Compile::current())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 463, "assert(" "compile == Compile::current()" ") failed", "sanity"
); ::breakpoint(); } } while (0)
;
464
465 compile->set_type_dict(NULL__null);
466 compile->set_clone_map(new Dict(cmpkey, hashkey, _compile->comp_arena()));
467 compile->clone_map().set_clone_idx(0);
468 compile->set_type_last_size(0);
469 compile->set_last_tf(NULL__null, NULL__null);
470 compile->set_indexSet_arena(NULL__null);
471 compile->set_indexSet_free_block_list(NULL__null);
472 compile->init_type_arena();
473 Type::Initialize(compile);
474 _compile->begin_method();
475 _compile->clone_map().set_debug(_compile->has_method() && _compile->directive()->CloneMapDebugOption);
476}
477CompileWrapper::~CompileWrapper() {
478 // simulate crash during compilation
479 assert(CICrashAt < 0 || _compile->compile_id() != CICrashAt, "just as planned")do { if (!(CICrashAt < 0 || _compile->compile_id() != CICrashAt
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 479, "assert(" "CICrashAt < 0 || _compile->compile_id() != CICrashAt"
") failed", "just as planned"); ::breakpoint(); } } while (0
)
;
480
481 _compile->end_method();
482 _compile->env()->set_compiler_data(NULL__null);
483}
484
485
486//----------------------------print_compile_messages---------------------------
487void Compile::print_compile_messages() {
488#ifndef PRODUCT
489 // Check if recompiling
490 if (!subsume_loads() && PrintOpto) {
491 // Recompiling without allowing machine instructions to subsume loads
492 tty->print_cr("*********************************************************");
493 tty->print_cr("** Bailout: Recompile without subsuming loads **");
494 tty->print_cr("*********************************************************");
495 }
496 if ((do_escape_analysis() != DoEscapeAnalysis) && PrintOpto) {
497 // Recompiling without escape analysis
498 tty->print_cr("*********************************************************");
499 tty->print_cr("** Bailout: Recompile without escape analysis **");
500 tty->print_cr("*********************************************************");
501 }
502 if (do_iterative_escape_analysis() != DoEscapeAnalysis && PrintOpto) {
503 // Recompiling without iterative escape analysis
504 tty->print_cr("*********************************************************");
505 tty->print_cr("** Bailout: Recompile without iterative escape analysis**");
506 tty->print_cr("*********************************************************");
507 }
508 if ((eliminate_boxing() != EliminateAutoBox) && PrintOpto) {
509 // Recompiling without boxing elimination
510 tty->print_cr("*********************************************************");
511 tty->print_cr("** Bailout: Recompile without boxing elimination **");
512 tty->print_cr("*********************************************************");
513 }
514 if ((do_locks_coarsening() != EliminateLocks) && PrintOpto) {
515 // Recompiling without locks coarsening
516 tty->print_cr("*********************************************************");
517 tty->print_cr("** Bailout: Recompile without locks coarsening **");
518 tty->print_cr("*********************************************************");
519 }
520 if (env()->break_at_compile()) {
521 // Open the debugger when compiling this method.
522 tty->print("### Breaking when compiling: ");
523 method()->print_short_name();
524 tty->cr();
525 BREAKPOINT::breakpoint();
526 }
527
528 if( PrintOpto ) {
529 if (is_osr_compilation()) {
530 tty->print("[OSR]%3d", _compile_id);
531 } else {
532 tty->print("%3d", _compile_id);
533 }
534 }
535#endif
536}
537
538// ============================================================================
539//------------------------------Compile standard-------------------------------
540debug_only( int Compile::_debug_idx = 100000; )int Compile::_debug_idx = 100000;
541
542// Compile a method. entry_bci is -1 for normal compilations and indicates
543// the continuation bci for on stack replacement.
544
545
546Compile::Compile( ciEnv* ci_env, ciMethod* target, int osr_bci,
547 Options options, DirectiveSet* directive)
548 : Phase(Compiler),
549 _compile_id(ci_env->compile_id()),
550 _options(options),
551 _method(target),
552 _entry_bci(osr_bci),
553 _ilt(NULL__null),
554 _stub_function(NULL__null),
555 _stub_name(NULL__null),
556 _stub_entry_point(NULL__null),
557 _max_node_limit(MaxNodeLimit),
558 _post_loop_opts_phase(false),
559 _inlining_progress(false),
560 _inlining_incrementally(false),
561 _do_cleanup(false),
562 _has_reserved_stack_access(target->has_reserved_stack_access()),
563#ifndef PRODUCT
564 _igv_idx(0),
565 _trace_opto_output(directive->TraceOptoOutputOption),
566 _print_ideal(directive->PrintIdealOption),
567#endif
568 _has_method_handle_invokes(false),
569 _clinit_barrier_on_entry(false),
570 _stress_seed(0),
571 _comp_arena(mtCompiler),
572 _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
573 _env(ci_env),
574 _directive(directive),
575 _log(ci_env->log()),
576 _failure_reason(NULL__null),
577 _intrinsics (comp_arena(), 0, 0, NULL__null),
578 _macro_nodes (comp_arena(), 8, 0, NULL__null),
579 _predicate_opaqs (comp_arena(), 8, 0, NULL__null),
580 _skeleton_predicate_opaqs (comp_arena(), 8, 0, NULL__null),
581 _expensive_nodes (comp_arena(), 8, 0, NULL__null),
582 _for_post_loop_igvn(comp_arena(), 8, 0, NULL__null),
583 _coarsened_locks (comp_arena(), 8, 0, NULL__null),
584 _congraph(NULL__null),
585 NOT_PRODUCT(_printer(NULL) COMMA)_printer(__null) ,
586 _dead_node_list(comp_arena()),
587 _dead_node_count(0),
588 _node_arena(mtCompiler),
589 _old_arena(mtCompiler),
590 _mach_constant_base_node(NULL__null),
591 _Compile_types(mtCompiler),
592 _initial_gvn(NULL__null),
593 _for_igvn(NULL__null),
594 _late_inlines(comp_arena(), 2, 0, NULL__null),
595 _string_late_inlines(comp_arena(), 2, 0, NULL__null),
596 _boxing_late_inlines(comp_arena(), 2, 0, NULL__null),
597 _vector_reboxing_late_inlines(comp_arena(), 2, 0, NULL__null),
598 _late_inlines_pos(0),
599 _number_of_mh_late_inlines(0),
600 _native_invokers(comp_arena(), 1, 0, NULL__null),
601 _print_inlining_stream(NULL__null),
602 _print_inlining_list(NULL__null),
603 _print_inlining_idx(0),
604 _print_inlining_output(NULL__null),
605 _replay_inline_data(NULL__null),
606 _java_calls(0),
607 _inner_loops(0),
608 _interpreter_frame_size(0)
609#ifndef PRODUCT
610 , _in_dump_cnt(0)
611#endif
612{
613 C = this;
614 CompileWrapper cw(this);
615
616 if (CITimeVerbose) {
617 tty->print(" ");
618 target->holder()->name()->print();
619 tty->print(".");
620 target->print_short_name();
621 tty->print(" ");
622 }
623 TraceTime t1("Total compilation time", &_t_totalCompilation, CITime, CITimeVerbose);
624 TraceTime t2(NULL__null, &_t_methodCompilation, CITime, false);
625
626#if defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_ABSTRACT_ASSEMBLY)
627 bool print_opto_assembly = directive->PrintOptoAssemblyOption;
628 // We can always print a disassembly, either abstract (hex dump) or
629 // with the help of a suitable hsdis library. Thus, we should not
630 // couple print_assembly and print_opto_assembly controls.
631 // But: always print opto and regular assembly on compile command 'print'.
632 bool print_assembly = directive->PrintAssemblyOption;
633 set_print_assembly(print_opto_assembly || print_assembly);
634#else
635 set_print_assembly(false); // must initialize.
636#endif
637
638#ifndef PRODUCT
639 set_parsed_irreducible_loop(false);
640
641 if (directive->ReplayInlineOption) {
642 _replay_inline_data = ciReplay::load_inline_data(method(), entry_bci(), ci_env->comp_level());
643 }
644#endif
645 set_print_inlining(directive->PrintInliningOption || PrintOptoInlining);
646 set_print_intrinsics(directive->PrintIntrinsicsOption);
647 set_has_irreducible_loop(true); // conservative until build_loop_tree() reset it
648
649 if (ProfileTraps RTM_OPT_ONLY( || UseRTMLocking )|| UseRTMLocking) {
650 // Make sure the method being compiled gets its own MDO,
651 // so we can at least track the decompile_count().
652 // Need MDO to record RTM code generation state.
653 method()->ensure_method_data();
654 }
655
656 Init(::AliasLevel);
657
658
659 print_compile_messages();
660
661 _ilt = InlineTree::build_inline_tree_root();
662
663 // Even if NO memory addresses are used, MergeMem nodes must have at least 1 slice
664 assert(num_alias_types() >= AliasIdxRaw, "")do { if (!(num_alias_types() >= AliasIdxRaw)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 664, "assert(" "num_alias_types() >= AliasIdxRaw" ") failed"
, ""); ::breakpoint(); } } while (0)
;
665
666#define MINIMUM_NODE_HASH1023 1023
667 // Node list that Iterative GVN will start with
668 Unique_Node_List for_igvn(comp_arena());
669 set_for_igvn(&for_igvn);
670
671 // GVN that will be run immediately on new nodes
672 uint estimated_size = method()->code_size()*4+64;
673 estimated_size = (estimated_size < MINIMUM_NODE_HASH1023 ? MINIMUM_NODE_HASH1023 : estimated_size);
674 PhaseGVN gvn(node_arena(), estimated_size);
675 set_initial_gvn(&gvn);
676
677 print_inlining_init();
678 { // Scope for timing the parser
679 TracePhase tp("parse", &timers[_t_parser]);
680
681 // Put top into the hash table ASAP.
682 initial_gvn()->transform_no_reclaim(top());
683
684 // Set up tf(), start(), and find a CallGenerator.
685 CallGenerator* cg = NULL__null;
686 if (is_osr_compilation()) {
687 const TypeTuple *domain = StartOSRNode::osr_domain();
688 const TypeTuple *range = TypeTuple::make_range(method()->signature());
689 init_tf(TypeFunc::make(domain, range));
690 StartNode* s = new StartOSRNode(root(), domain);
691 initial_gvn()->set_type_bottom(s);
692 init_start(s);
693 cg = CallGenerator::for_osr(method(), entry_bci());
694 } else {
695 // Normal case.
696 init_tf(TypeFunc::make(method()));
697 StartNode* s = new StartNode(root(), tf()->domain());
698 initial_gvn()->set_type_bottom(s);
699 init_start(s);
700 if (method()->intrinsic_id() == vmIntrinsics::_Reference_get) {
701 // With java.lang.ref.reference.get() we must go through the
702 // intrinsic - even when get() is the root
703 // method of the compile - so that, if necessary, the value in
704 // the referent field of the reference object gets recorded by
705 // the pre-barrier code.
706 cg = find_intrinsic(method(), false);
707 }
708 if (cg == NULL__null) {
709 float past_uses = method()->interpreter_invocation_count();
710 float expected_uses = past_uses;
711 cg = CallGenerator::for_inline(method(), expected_uses);
712 }
713 }
714 if (failing()) return;
715 if (cg == NULL__null) {
716 record_method_not_compilable("cannot parse method");
717 return;
718 }
719 JVMState* jvms = build_start_state(start(), tf());
720 if ((jvms = cg->generate(jvms)) == NULL__null) {
721 if (!failure_reason_is(C2Compiler::retry_class_loading_during_parsing())) {
722 record_method_not_compilable("method parse failed");
723 }
724 return;
725 }
726 GraphKit kit(jvms);
727
728 if (!kit.stopped()) {
729 // Accept return values, and transfer control we know not where.
730 // This is done by a special, unique ReturnNode bound to root.
731 return_values(kit.jvms());
732 }
733
734 if (kit.has_exceptions()) {
735 // Any exceptions that escape from this call must be rethrown
736 // to whatever caller is dynamically above us on the stack.
737 // This is done by a special, unique RethrowNode bound to root.
738 rethrow_exceptions(kit.transfer_exceptions_into_jvms());
739 }
740
741 assert(IncrementalInline || (_late_inlines.length() == 0 && !has_mh_late_inlines()), "incremental inlining is off")do { if (!(IncrementalInline || (_late_inlines.length() == 0 &&
!has_mh_late_inlines()))) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 741, "assert(" "IncrementalInline || (_late_inlines.length() == 0 && !has_mh_late_inlines())"
") failed", "incremental inlining is off"); ::breakpoint(); }
} while (0)
;
742
743 if (_late_inlines.length() == 0 && !has_mh_late_inlines() && !failing() && has_stringbuilder()) {
744 inline_string_calls(true);
745 }
746
747 if (failing()) return;
748
749 print_method(PHASE_BEFORE_REMOVEUSELESS, 3);
750
751 // Remove clutter produced by parsing.
752 if (!failing()) {
753 ResourceMark rm;
754 PhaseRemoveUseless pru(initial_gvn(), &for_igvn);
755 }
756 }
757
758 // Note: Large methods are capped off in do_one_bytecode().
759 if (failing()) return;
760
761 // After parsing, node notes are no longer automagic.
762 // They must be propagated by register_new_node_with_optimizer(),
763 // clone(), or the like.
764 set_default_node_notes(NULL__null);
765
766#ifndef PRODUCT
767 if (should_print(1)) {
768 _printer->print_inlining();
769 }
770#endif
771
772 if (failing()) return;
773 NOT_PRODUCT( verify_graph_edges(); )verify_graph_edges();
774
775 // If any phase is randomized for stress testing, seed random number
776 // generation and log the seed for repeatability.
777 if (StressLCM || StressGCM || StressIGVN || StressCCP) {
778 if (FLAG_IS_DEFAULT(StressSeed)(JVMFlag::is_default(Flag_StressSeed_enum)) || (FLAG_IS_ERGO(StressSeed)(JVMFlag::is_ergo(Flag_StressSeed_enum)) && RepeatCompilation)) {
779 _stress_seed = static_cast<uint>(Ticks::now().nanoseconds());
780 FLAG_SET_ERGO(StressSeed, _stress_seed)(Flag_StressSeed_set((_stress_seed), JVMFlagOrigin::ERGONOMIC
))
;
781 } else {
782 _stress_seed = StressSeed;
783 }
784 if (_log != NULL__null) {
785 _log->elem("stress_test seed='%u'", _stress_seed);
786 }
787 }
788
789 // Now optimize
790 Optimize();
791 if (failing()) return;
792 NOT_PRODUCT( verify_graph_edges(); )verify_graph_edges();
793
794#ifndef PRODUCT
795 if (print_ideal()) {
796 ttyLocker ttyl; // keep the following output all in one block
797 // This output goes directly to the tty, not the compiler log.
798 // To enable tools to match it up with the compilation activity,
799 // be sure to tag this tty output with the compile ID.
800 if (xtty != NULL__null) {
801 xtty->head("ideal compile_id='%d'%s", compile_id(),
802 is_osr_compilation() ? " compile_kind='osr'" :
803 "");
804 }
805 root()->dump(9999);
806 if (xtty != NULL__null) {
807 xtty->tail("ideal");
808 }
809 }
810#endif
811
812#ifdef ASSERT1
813 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
814 bs->verify_gc_barriers(this, BarrierSetC2::BeforeCodeGen);
815#endif
816
817 // Dump compilation data to replay it.
818 if (directive->DumpReplayOption) {
819 env()->dump_replay_data(_compile_id);
820 }
821 if (directive->DumpInlineOption && (ilt() != NULL__null)) {
822 env()->dump_inline_data(_compile_id);
823 }
824
825 // Now that we know the size of all the monitors we can add a fixed slot
826 // for the original deopt pc.
827 int next_slot = fixed_slots() + (sizeof(address) / VMRegImpl::stack_slot_size);
828 set_fixed_slots(next_slot);
829
830 // Compute when to use implicit null checks. Used by matching trap based
831 // nodes and NullCheck optimization.
832 set_allowed_deopt_reasons();
833
834 // Now generate code
835 Code_Gen();
836}
837
838//------------------------------Compile----------------------------------------
839// Compile a runtime stub
840Compile::Compile( ciEnv* ci_env,
841 TypeFunc_generator generator,
842 address stub_function,
843 const char *stub_name,
844 int is_fancy_jump,
845 bool pass_tls,
846 bool return_pc,
847 DirectiveSet* directive)
848 : Phase(Compiler),
849 _compile_id(0),
850 _options(Options::for_runtime_stub()),
851 _method(NULL__null),
852 _entry_bci(InvocationEntryBci),
853 _stub_function(stub_function),
854 _stub_name(stub_name),
855 _stub_entry_point(NULL__null),
856 _max_node_limit(MaxNodeLimit),
857 _post_loop_opts_phase(false),
858 _inlining_progress(false),
859 _inlining_incrementally(false),
860 _has_reserved_stack_access(false),
861#ifndef PRODUCT
862 _igv_idx(0),
863 _trace_opto_output(directive->TraceOptoOutputOption),
864 _print_ideal(directive->PrintIdealOption),
865#endif
866 _has_method_handle_invokes(false),
867 _clinit_barrier_on_entry(false),
868 _stress_seed(0),
869 _comp_arena(mtCompiler),
870 _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
871 _env(ci_env),
872 _directive(directive),
873 _log(ci_env->log()),
874 _failure_reason(NULL__null),
875 _congraph(NULL__null),
876 NOT_PRODUCT(_printer(NULL) COMMA)_printer(__null) ,
877 _dead_node_list(comp_arena()),
878 _dead_node_count(0),
879 _node_arena(mtCompiler),
880 _old_arena(mtCompiler),
881 _mach_constant_base_node(NULL__null),
882 _Compile_types(mtCompiler),
883 _initial_gvn(NULL__null),
884 _for_igvn(NULL__null),
885 _number_of_mh_late_inlines(0),
886 _native_invokers(),
887 _print_inlining_stream(NULL__null),
888 _print_inlining_list(NULL__null),
889 _print_inlining_idx(0),
890 _print_inlining_output(NULL__null),
891 _replay_inline_data(NULL__null),
892 _java_calls(0),
893 _inner_loops(0),
894 _interpreter_frame_size(0),
895#ifndef PRODUCT
896 _in_dump_cnt(0),
897#endif
898 _allowed_reasons(0) {
899 C = this;
900
901 TraceTime t1(NULL__null, &_t_totalCompilation, CITime, false);
902 TraceTime t2(NULL__null, &_t_stubCompilation, CITime, false);
903
904#ifndef PRODUCT
905 set_print_assembly(PrintFrameConverterAssembly);
906 set_parsed_irreducible_loop(false);
907#else
908 set_print_assembly(false); // Must initialize.
909#endif
910 set_has_irreducible_loop(false); // no loops
911
912 CompileWrapper cw(this);
913 Init(/*AliasLevel=*/ 0);
914 init_tf((*generator)());
915
916 {
917 // The following is a dummy for the sake of GraphKit::gen_stub
918 Unique_Node_List for_igvn(comp_arena());
919 set_for_igvn(&for_igvn); // not used, but some GraphKit guys push on this
920 PhaseGVN gvn(Thread::current()->resource_area(),255);
921 set_initial_gvn(&gvn); // not significant, but GraphKit guys use it pervasively
922 gvn.transform_no_reclaim(top());
923
924 GraphKit kit;
925 kit.gen_stub(stub_function, stub_name, is_fancy_jump, pass_tls, return_pc);
926 }
927
928 NOT_PRODUCT( verify_graph_edges(); )verify_graph_edges();
929
930 Code_Gen();
931}
932
933//------------------------------Init-------------------------------------------
934// Prepare for a single compilation
935void Compile::Init(int aliaslevel) {
936 _unique = 0;
937 _regalloc = NULL__null;
938
939 _tf = NULL__null; // filled in later
940 _top = NULL__null; // cached later
941 _matcher = NULL__null; // filled in later
942 _cfg = NULL__null; // filled in later
943
944 IA32_ONLY( set_24_bit_selection_and_mode(true, false); )
945
946 _node_note_array = NULL__null;
947 _default_node_notes = NULL__null;
948 DEBUG_ONLY( _modified_nodes = NULL; )_modified_nodes = __null; // Used in Optimize()
949
950 _immutable_memory = NULL__null; // filled in at first inquiry
951
952 // Globally visible Nodes
953 // First set TOP to NULL to give safe behavior during creation of RootNode
954 set_cached_top_node(NULL__null);
955 set_root(new RootNode());
956 // Now that you have a Root to point to, create the real TOP
957 set_cached_top_node( new ConNode(Type::TOP) );
958 set_recent_alloc(NULL__null, NULL__null);
959
960 // Create Debug Information Recorder to record scopes, oopmaps, etc.
961 env()->set_oop_recorder(new OopRecorder(env()->arena()));
962 env()->set_debug_info(new DebugInformationRecorder(env()->oop_recorder()));
963 env()->set_dependencies(new Dependencies(env()));
964
965 _fixed_slots = 0;
966 set_has_split_ifs(false);
967 set_has_loops(false); // first approximation
968 set_has_stringbuilder(false);
969 set_has_boxed_value(false);
970 _trap_can_recompile = false; // no traps emitted yet
971 _major_progress = true; // start out assuming good things will happen
972 set_has_unsafe_access(false);
973 set_max_vector_size(0);
974 set_clear_upper_avx(false); //false as default for clear upper bits of ymm registers
975 Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
976 set_decompile_count(0);
977
978 set_do_freq_based_layout(_directive->BlockLayoutByFrequencyOption);
979 _loop_opts_cnt = LoopOptsCount;
980 set_do_inlining(Inline);
981 set_max_inline_size(MaxInlineSize);
982 set_freq_inline_size(FreqInlineSize);
983 set_do_scheduling(OptoScheduling);
984
985 set_do_vector_loop(false);
986
987 if (AllowVectorizeOnDemand) {
988 if (has_method() && (_directive->VectorizeOption || _directive->VectorizeDebugOption)) {
989 set_do_vector_loop(true);
990 NOT_PRODUCT(if (do_vector_loop() && Verbose) {tty->print("Compile::Init: do vectorized loops (SIMD like) for method %s\n", method()->name()->as_quoted_ascii());})if (do_vector_loop() && Verbose) {tty->print("Compile::Init: do vectorized loops (SIMD like) for method %s\n"
, method()->name()->as_quoted_ascii());}
991 } else if (has_method() && method()->name() != 0 &&
992 method()->intrinsic_id() == vmIntrinsics::_forEachRemaining) {
993 set_do_vector_loop(true);
994 }
995 }
996 set_use_cmove(UseCMoveUnconditionally /* || do_vector_loop()*/); //TODO: consider do_vector_loop() mandate use_cmove unconditionally
997 NOT_PRODUCT(if (use_cmove() && Verbose && has_method()) {tty->print("Compile::Init: use CMove without profitability tests for method %s\n", method()->name()->as_quoted_ascii());})if (use_cmove() && Verbose && has_method()) {
tty->print("Compile::Init: use CMove without profitability tests for method %s\n"
, method()->name()->as_quoted_ascii());}
998
999 set_age_code(has_method() && method()->profile_aging());
1000 set_rtm_state(NoRTM); // No RTM lock eliding by default
1001 _max_node_limit = _directive->MaxNodeLimitOption;
1002
1003#if INCLUDE_RTM_OPT1
1004 if (UseRTMLocking && has_method() && (method()->method_data_or_null() != NULL__null)) {
1005 int rtm_state = method()->method_data()->rtm_state();
1006 if (method_has_option(CompileCommand::NoRTMLockEliding) || ((rtm_state & NoRTM) != 0)) {
1007 // Don't generate RTM lock eliding code.
1008 set_rtm_state(NoRTM);
1009 } else if (method_has_option(CompileCommand::UseRTMLockEliding) || ((rtm_state & UseRTM) != 0) || !UseRTMDeopt) {
1010 // Generate RTM lock eliding code without abort ratio calculation code.
1011 set_rtm_state(UseRTM);
1012 } else if (UseRTMDeopt) {
1013 // Generate RTM lock eliding code and include abort ratio calculation
1014 // code if UseRTMDeopt is on.
1015 set_rtm_state(ProfileRTM);
1016 }
1017 }
1018#endif
1019 if (VM_Version::supports_fast_class_init_checks() && has_method() && !is_osr_compilation() && method()->needs_clinit_barrier()) {
1020 set_clinit_barrier_on_entry(true);
1021 }
1022 if (debug_info()->recording_non_safepoints()) {
1023 set_node_note_array(new(comp_arena()) GrowableArray<Node_Notes*>
1024 (comp_arena(), 8, 0, NULL__null));
1025 set_default_node_notes(Node_Notes::make(this));
1026 }
1027
1028 // // -- Initialize types before each compile --
1029 // // Update cached type information
1030 // if( _method && _method->constants() )
1031 // Type::update_loaded_types(_method, _method->constants());
1032
1033 // Init alias_type map.
1034 if (!do_escape_analysis() && aliaslevel == 3) {
1035 aliaslevel = 2; // No unique types without escape analysis
1036 }
1037 _AliasLevel = aliaslevel;
1038 const int grow_ats = 16;
1039 _max_alias_types = grow_ats;
1040 _alias_types = NEW_ARENA_ARRAY(comp_arena(), AliasType*, grow_ats)(AliasType**) (comp_arena())->Amalloc((grow_ats) * sizeof(
AliasType*))
;
1041 AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType, grow_ats)(AliasType*) (comp_arena())->Amalloc((grow_ats) * sizeof(AliasType
))
;
1042 Copy::zero_to_bytes(ats, sizeof(AliasType)*grow_ats);
1043 {
1044 for (int i = 0; i < grow_ats; i++) _alias_types[i] = &ats[i];
1045 }
1046 // Initialize the first few types.
1047 _alias_types[AliasIdxTop]->Init(AliasIdxTop, NULL__null);
1048 _alias_types[AliasIdxBot]->Init(AliasIdxBot, TypePtr::BOTTOM);
1049 _alias_types[AliasIdxRaw]->Init(AliasIdxRaw, TypeRawPtr::BOTTOM);
1050 _num_alias_types = AliasIdxRaw+1;
1051 // Zero out the alias type cache.
1052 Copy::zero_to_bytes(_alias_cache, sizeof(_alias_cache));
1053 // A NULL adr_type hits in the cache right away. Preload the right answer.
1054 probe_alias_cache(NULL__null)->_index = AliasIdxTop;
1055
1056#ifdef ASSERT1
1057 _type_verify_symmetry = true;
1058 _phase_optimize_finished = false;
1059 _exception_backedge = false;
1060#endif
1061}
1062
1063//---------------------------init_start----------------------------------------
1064// Install the StartNode on this compile object.
1065void Compile::init_start(StartNode* s) {
1066 if (failing())
1067 return; // already failing
1068 assert(s == start(), "")do { if (!(s == start())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1068, "assert(" "s == start()" ") failed", ""); ::breakpoint
(); } } while (0)
;
1069}
1070
1071/**
1072 * Return the 'StartNode'. We must not have a pending failure, since the ideal graph
1073 * can be in an inconsistent state, i.e., we can get segmentation faults when traversing
1074 * the ideal graph.
1075 */
1076StartNode* Compile::start() const {
1077 assert (!failing(), "Must not have pending failure. Reason is: %s", failure_reason())do { if (!(!failing())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1077, "assert(" "!failing()" ") failed", "Must not have pending failure. Reason is: %s"
, failure_reason()); ::breakpoint(); } } while (0)
;
1078 for (DUIterator_Fast imax, i = root()->fast_outs(imax); i < imax; i++) {
1079 Node* start = root()->fast_out(i);
1080 if (start->is_Start()) {
1081 return start->as_Start();
1082 }
1083 }
1084 fatal("Did not find Start node!")do { (*g_assert_poison) = 'X';; report_fatal(INTERNAL_ERROR, "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1084, "Did not find Start node!"); ::breakpoint(); } while (
0)
;
1085 return NULL__null;
1086}
1087
1088//-------------------------------immutable_memory-------------------------------------
1089// Access immutable memory
1090Node* Compile::immutable_memory() {
1091 if (_immutable_memory != NULL__null) {
1092 return _immutable_memory;
1093 }
1094 StartNode* s = start();
1095 for (DUIterator_Fast imax, i = s->fast_outs(imax); true; i++) {
1096 Node *p = s->fast_out(i);
1097 if (p != s && p->as_Proj()->_con == TypeFunc::Memory) {
1098 _immutable_memory = p;
1099 return _immutable_memory;
1100 }
1101 }
1102 ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here(
"/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1102); ::breakpoint(); } while (0)
;
1103 return NULL__null;
1104}
1105
1106//----------------------set_cached_top_node------------------------------------
1107// Install the cached top node, and make sure Node::is_top works correctly.
1108void Compile::set_cached_top_node(Node* tn) {
1109 if (tn != NULL__null) verify_top(tn);
1110 Node* old_top = _top;
1111 _top = tn;
1112 // Calling Node::setup_is_top allows the nodes the chance to adjust
1113 // their _out arrays.
1114 if (_top != NULL__null) _top->setup_is_top();
1115 if (old_top != NULL__null) old_top->setup_is_top();
1116 assert(_top == NULL || top()->is_top(), "")do { if (!(_top == __null || top()->is_top())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1116, "assert(" "_top == __null || top()->is_top()" ") failed"
, ""); ::breakpoint(); } } while (0)
;
1117}
1118
1119#ifdef ASSERT1
1120uint Compile::count_live_nodes_by_graph_walk() {
1121 Unique_Node_List useful(comp_arena());
1122 // Get useful node list by walking the graph.
1123 identify_useful_nodes(useful);
1124 return useful.size();
1125}
1126
1127void Compile::print_missing_nodes() {
1128
1129 // Return if CompileLog is NULL and PrintIdealNodeCount is false.
1130 if ((_log == NULL__null) && (! PrintIdealNodeCount)) {
1131 return;
1132 }
1133
1134 // This is an expensive function. It is executed only when the user
1135 // specifies VerifyIdealNodeCount option or otherwise knows the
1136 // additional work that needs to be done to identify reachable nodes
1137 // by walking the flow graph and find the missing ones using
1138 // _dead_node_list.
1139
1140 Unique_Node_List useful(comp_arena());
1141 // Get useful node list by walking the graph.
1142 identify_useful_nodes(useful);
1143
1144 uint l_nodes = C->live_nodes();
1145 uint l_nodes_by_walk = useful.size();
1146
1147 if (l_nodes != l_nodes_by_walk) {
1148 if (_log != NULL__null) {
1149 _log->begin_head("mismatched_nodes count='%d'", abs((int) (l_nodes - l_nodes_by_walk)));
1150 _log->stamp();
1151 _log->end_head();
1152 }
1153 VectorSet& useful_member_set = useful.member_set();
1154 int last_idx = l_nodes_by_walk;
1155 for (int i = 0; i < last_idx; i++) {
1156 if (useful_member_set.test(i)) {
1157 if (_dead_node_list.test(i)) {
1158 if (_log != NULL__null) {
1159 _log->elem("mismatched_node_info node_idx='%d' type='both live and dead'", i);
1160 }
1161 if (PrintIdealNodeCount) {
1162 // Print the log message to tty
1163 tty->print_cr("mismatched_node idx='%d' both live and dead'", i);
1164 useful.at(i)->dump();
1165 }
1166 }
1167 }
1168 else if (! _dead_node_list.test(i)) {
1169 if (_log != NULL__null) {
1170 _log->elem("mismatched_node_info node_idx='%d' type='neither live nor dead'", i);
1171 }
1172 if (PrintIdealNodeCount) {
1173 // Print the log message to tty
1174 tty->print_cr("mismatched_node idx='%d' type='neither live nor dead'", i);
1175 }
1176 }
1177 }
1178 if (_log != NULL__null) {
1179 _log->tail("mismatched_nodes");
1180 }
1181 }
1182}
1183void Compile::record_modified_node(Node* n) {
1184 if (_modified_nodes != NULL__null && !_inlining_incrementally && !n->is_Con()) {
1185 _modified_nodes->push(n);
1186 }
1187}
1188
1189void Compile::remove_modified_node(Node* n) {
1190 if (_modified_nodes != NULL__null) {
1191 _modified_nodes->remove(n);
1192 }
1193}
1194#endif
1195
1196#ifndef PRODUCT
1197void Compile::verify_top(Node* tn) const {
1198 if (tn != NULL__null) {
1199 assert(tn->is_Con(), "top node must be a constant")do { if (!(tn->is_Con())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1199, "assert(" "tn->is_Con()" ") failed", "top node must be a constant"
); ::breakpoint(); } } while (0)
;
1200 assert(((ConNode*)tn)->type() == Type::TOP, "top node must have correct type")do { if (!(((ConNode*)tn)->type() == Type::TOP)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1200, "assert(" "((ConNode*)tn)->type() == Type::TOP" ") failed"
, "top node must have correct type"); ::breakpoint(); } } while
(0)
;
1201 assert(tn->in(0) != NULL, "must have live top node")do { if (!(tn->in(0) != __null)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1201, "assert(" "tn->in(0) != __null" ") failed", "must have live top node"
); ::breakpoint(); } } while (0)
;
1202 }
1203}
1204#endif
1205
1206
1207///-------------------Managing Per-Node Debug & Profile Info-------------------
1208
1209void Compile::grow_node_notes(GrowableArray<Node_Notes*>* arr, int grow_by) {
1210 guarantee(arr != NULL, "")do { if (!(arr != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1210, "guarantee(" "arr != NULL" ") failed", ""); ::breakpoint
(); } } while (0)
;
1211 int num_blocks = arr->length();
1212 if (grow_by < num_blocks) grow_by = num_blocks;
1213 int num_notes = grow_by * _node_notes_block_size;
1214 Node_Notes* notes = NEW_ARENA_ARRAY(node_arena(), Node_Notes, num_notes)(Node_Notes*) (node_arena())->Amalloc((num_notes) * sizeof
(Node_Notes))
;
1215 Copy::zero_to_bytes(notes, num_notes * sizeof(Node_Notes));
1216 while (num_notes > 0) {
1217 arr->append(notes);
1218 notes += _node_notes_block_size;
1219 num_notes -= _node_notes_block_size;
1220 }
1221 assert(num_notes == 0, "exact multiple, please")do { if (!(num_notes == 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1221, "assert(" "num_notes == 0" ") failed", "exact multiple, please"
); ::breakpoint(); } } while (0)
;
1222}
1223
1224bool Compile::copy_node_notes_to(Node* dest, Node* source) {
1225 if (source == NULL__null || dest == NULL__null) return false;
1226
1227 if (dest->is_Con())
1228 return false; // Do not push debug info onto constants.
1229
1230#ifdef ASSERT1
1231 // Leave a bread crumb trail pointing to the original node:
1232 if (dest != NULL__null && dest != source && dest->debug_orig() == NULL__null) {
1233 dest->set_debug_orig(source);
1234 }
1235#endif
1236
1237 if (node_note_array() == NULL__null)
1238 return false; // Not collecting any notes now.
1239
1240 // This is a copy onto a pre-existing node, which may already have notes.
1241 // If both nodes have notes, do not overwrite any pre-existing notes.
1242 Node_Notes* source_notes = node_notes_at(source->_idx);
1243 if (source_notes == NULL__null || source_notes->is_clear()) return false;
1244 Node_Notes* dest_notes = node_notes_at(dest->_idx);
1245 if (dest_notes == NULL__null || dest_notes->is_clear()) {
1246 return set_node_notes_at(dest->_idx, source_notes);
1247 }
1248
1249 Node_Notes merged_notes = (*source_notes);
1250 // The order of operations here ensures that dest notes will win...
1251 merged_notes.update_from(dest_notes);
1252 return set_node_notes_at(dest->_idx, &merged_notes);
1253}
1254
1255
1256//--------------------------allow_range_check_smearing-------------------------
1257// Gating condition for coalescing similar range checks.
1258// Sometimes we try 'speculatively' replacing a series of a range checks by a
1259// single covering check that is at least as strong as any of them.
1260// If the optimization succeeds, the simplified (strengthened) range check
1261// will always succeed. If it fails, we will deopt, and then give up
1262// on the optimization.
1263bool Compile::allow_range_check_smearing() const {
1264 // If this method has already thrown a range-check,
1265 // assume it was because we already tried range smearing
1266 // and it failed.
1267 uint already_trapped = trap_count(Deoptimization::Reason_range_check);
1268 return !already_trapped;
1269}
1270
1271
1272//------------------------------flatten_alias_type-----------------------------
1273const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const {
1274 int offset = tj->offset();
1275 TypePtr::PTR ptr = tj->ptr();
1276
1277 // Known instance (scalarizable allocation) alias only with itself.
1278 bool is_known_inst = tj->isa_oopptr() != NULL__null &&
1279 tj->is_oopptr()->is_known_instance();
1280
1281 // Process weird unsafe references.
1282 if (offset == Type::OffsetBot && (tj->isa_instptr() /*|| tj->isa_klassptr()*/)) {
1283 assert(InlineUnsafeOps, "indeterminate pointers come only from unsafe ops")do { if (!(InlineUnsafeOps)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1283, "assert(" "InlineUnsafeOps" ") failed", "indeterminate pointers come only from unsafe ops"
); ::breakpoint(); } } while (0)
;
1284 assert(!is_known_inst, "scalarizable allocation should not have unsafe references")do { if (!(!is_known_inst)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1284, "assert(" "!is_known_inst" ") failed", "scalarizable allocation should not have unsafe references"
); ::breakpoint(); } } while (0)
;
1285 tj = TypeOopPtr::BOTTOM;
1286 ptr = tj->ptr();
1287 offset = tj->offset();
1288 }
1289
1290 // Array pointers need some flattening
1291 const TypeAryPtr *ta = tj->isa_aryptr();
1292 if (ta && ta->is_stable()) {
1293 // Erase stability property for alias analysis.
1294 tj = ta = ta->cast_to_stable(false);
1295 }
1296 if( ta && is_known_inst ) {
1297 if ( offset != Type::OffsetBot &&
1298 offset > arrayOopDesc::length_offset_in_bytes() ) {
1299 offset = Type::OffsetBot; // Flatten constant access into array body only
1300 tj = ta = TypeAryPtr::make(ptr, ta->ary(), ta->klass(), true, offset, ta->instance_id());
1301 }
1302 } else if( ta && _AliasLevel >= 2 ) {
1303 // For arrays indexed by constant indices, we flatten the alias
1304 // space to include all of the array body. Only the header, klass
1305 // and array length can be accessed un-aliased.
1306 if( offset != Type::OffsetBot ) {
1307 if( ta->const_oop() ) { // MethodData* or Method*
1308 offset = Type::OffsetBot; // Flatten constant access into array body
1309 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),ta->ary(),ta->klass(),false,offset);
1310 } else if( offset == arrayOopDesc::length_offset_in_bytes() ) {
1311 // range is OK as-is.
1312 tj = ta = TypeAryPtr::RANGE;
1313 } else if( offset == oopDesc::klass_offset_in_bytes() ) {
1314 tj = TypeInstPtr::KLASS; // all klass loads look alike
1315 ta = TypeAryPtr::RANGE; // generic ignored junk
1316 ptr = TypePtr::BotPTR;
1317 } else if( offset == oopDesc::mark_offset_in_bytes() ) {
1318 tj = TypeInstPtr::MARK;
1319 ta = TypeAryPtr::RANGE; // generic ignored junk
1320 ptr = TypePtr::BotPTR;
1321 } else { // Random constant offset into array body
1322 offset = Type::OffsetBot; // Flatten constant access into array body
1323 tj = ta = TypeAryPtr::make(ptr,ta->ary(),ta->klass(),false,offset);
1324 }
1325 }
1326 // Arrays of fixed size alias with arrays of unknown size.
1327 if (ta->size() != TypeInt::POS) {
1328 const TypeAry *tary = TypeAry::make(ta->elem(), TypeInt::POS);
1329 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,ta->klass(),false,offset);
1330 }
1331 // Arrays of known objects become arrays of unknown objects.
1332 if (ta->elem()->isa_narrowoop() && ta->elem() != TypeNarrowOop::BOTTOM) {
1333 const TypeAry *tary = TypeAry::make(TypeNarrowOop::BOTTOM, ta->size());
1334 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL__null,false,offset);
1335 }
1336 if (ta->elem()->isa_oopptr() && ta->elem() != TypeInstPtr::BOTTOM) {
1337 const TypeAry *tary = TypeAry::make(TypeInstPtr::BOTTOM, ta->size());
1338 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL__null,false,offset);
1339 }
1340 // Arrays of bytes and of booleans both use 'bastore' and 'baload' so
1341 // cannot be distinguished by bytecode alone.
1342 if (ta->elem() == TypeInt::BOOL) {
1343 const TypeAry *tary = TypeAry::make(TypeInt::BYTE, ta->size());
1344 ciKlass* aklass = ciTypeArrayKlass::make(T_BYTE);
1345 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,aklass,false,offset);
1346 }
1347 // During the 2nd round of IterGVN, NotNull castings are removed.
1348 // Make sure the Bottom and NotNull variants alias the same.
1349 // Also, make sure exact and non-exact variants alias the same.
1350 if (ptr == TypePtr::NotNull || ta->klass_is_exact() || ta->speculative() != NULL__null) {
1351 tj = ta = TypeAryPtr::make(TypePtr::BotPTR,ta->ary(),ta->klass(),false,offset);
1352 }
1353 }
1354
1355 // Oop pointers need some flattening
1356 const TypeInstPtr *to = tj->isa_instptr();
1357 if( to && _AliasLevel >= 2 && to != TypeOopPtr::BOTTOM ) {
1358 ciInstanceKlass *k = to->klass()->as_instance_klass();
1359 if( ptr == TypePtr::Constant ) {
1360 if (to->klass() != ciEnv::current()->Class_klass() ||
1361 offset < k->layout_helper_size_in_bytes()) {
1362 // No constant oop pointers (such as Strings); they alias with
1363 // unknown strings.
1364 assert(!is_known_inst, "not scalarizable allocation")do { if (!(!is_known_inst)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1364, "assert(" "!is_known_inst" ") failed", "not scalarizable allocation"
); ::breakpoint(); } } while (0)
;
1365 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset);
1366 }
1367 } else if( is_known_inst ) {
1368 tj = to; // Keep NotNull and klass_is_exact for instance type
1369 } else if( ptr == TypePtr::NotNull || to->klass_is_exact() ) {
1370 // During the 2nd round of IterGVN, NotNull castings are removed.
1371 // Make sure the Bottom and NotNull variants alias the same.
1372 // Also, make sure exact and non-exact variants alias the same.
1373 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset);
1374 }
1375 if (to->speculative() != NULL__null) {
1376 tj = to = TypeInstPtr::make(to->ptr(),to->klass(),to->klass_is_exact(),to->const_oop(),to->offset(), to->instance_id());
1377 }
1378 // Canonicalize the holder of this field
1379 if (offset >= 0 && offset < instanceOopDesc::base_offset_in_bytes()) {
1380 // First handle header references such as a LoadKlassNode, even if the
1381 // object's klass is unloaded at compile time (4965979).
1382 if (!is_known_inst) { // Do it only for non-instance types
1383 tj = to = TypeInstPtr::make(TypePtr::BotPTR, env()->Object_klass(), false, NULL__null, offset);
1384 }
1385 } else if (offset < 0 || offset >= k->layout_helper_size_in_bytes()) {
1386 // Static fields are in the space above the normal instance
1387 // fields in the java.lang.Class instance.
1388 if (to->klass() != ciEnv::current()->Class_klass()) {
1389 to = NULL__null;
1390 tj = TypeOopPtr::BOTTOM;
1391 offset = tj->offset();
1392 }
1393 } else {
1394 ciInstanceKlass *canonical_holder = k->get_canonical_holder(offset);
1395 assert(offset < canonical_holder->layout_helper_size_in_bytes(), "")do { if (!(offset < canonical_holder->layout_helper_size_in_bytes
())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1395, "assert(" "offset < canonical_holder->layout_helper_size_in_bytes()"
") failed", ""); ::breakpoint(); } } while (0)
;
1396 if (!k->equals(canonical_holder) || tj->offset() != offset) {
1397 if( is_known_inst ) {
1398 tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, true, NULL__null, offset, to->instance_id());
1399 } else {
1400 tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, false, NULL__null, offset);
1401 }
1402 }
1403 }
1404 }
1405
1406 // Klass pointers to object array klasses need some flattening
1407 const TypeKlassPtr *tk = tj->isa_klassptr();
1408 if( tk ) {
1409 // If we are referencing a field within a Klass, we need
1410 // to assume the worst case of an Object. Both exact and
1411 // inexact types must flatten to the same alias class so
1412 // use NotNull as the PTR.
1413 if ( offset == Type::OffsetBot || (offset >= 0 && (size_t)offset < sizeof(Klass)) ) {
1414
1415 tj = tk = TypeKlassPtr::make(TypePtr::NotNull,
1416 TypeInstKlassPtr::OBJECT->klass(),
1417 offset);
1418 }
1419
1420 ciKlass* klass = tk->klass();
1421 if( klass->is_obj_array_klass() ) {
1422 ciKlass* k = TypeAryPtr::OOPS->klass();
1423 if( !k || !k->is_loaded() ) // Only fails for some -Xcomp runs
1424 k = TypeInstPtr::BOTTOM->klass();
1425 tj = tk = TypeKlassPtr::make( TypePtr::NotNull, k, offset );
1426 }
1427
1428 // Check for precise loads from the primary supertype array and force them
1429 // to the supertype cache alias index. Check for generic array loads from
1430 // the primary supertype array and also force them to the supertype cache
1431 // alias index. Since the same load can reach both, we need to merge
1432 // these 2 disparate memories into the same alias class. Since the
1433 // primary supertype array is read-only, there's no chance of confusion
1434 // where we bypass an array load and an array store.
1435 int primary_supers_offset = in_bytes(Klass::primary_supers_offset());
1436 if (offset == Type::OffsetBot ||
1437 (offset >= primary_supers_offset &&
1438 offset < (int)(primary_supers_offset + Klass::primary_super_limit() * wordSize)) ||
1439 offset == (int)in_bytes(Klass::secondary_super_cache_offset())) {
1440 offset = in_bytes(Klass::secondary_super_cache_offset());
1441 tj = tk = TypeKlassPtr::make( TypePtr::NotNull, tk->klass(), offset );
1442 }
1443 }
1444
1445 // Flatten all Raw pointers together.
1446 if (tj->base() == Type::RawPtr)
1447 tj = TypeRawPtr::BOTTOM;
1448
1449 if (tj->base() == Type::AnyPtr)
1450 tj = TypePtr::BOTTOM; // An error, which the caller must check for.
1451
1452 // Flatten all to bottom for now
1453 switch( _AliasLevel ) {
1454 case 0:
1455 tj = TypePtr::BOTTOM;
1456 break;
1457 case 1: // Flatten to: oop, static, field or array
1458 switch (tj->base()) {
1459 //case Type::AryPtr: tj = TypeAryPtr::RANGE; break;
1460 case Type::RawPtr: tj = TypeRawPtr::BOTTOM; break;
1461 case Type::AryPtr: // do not distinguish arrays at all
1462 case Type::InstPtr: tj = TypeInstPtr::BOTTOM; break;
1463 case Type::KlassPtr:
1464 case Type::AryKlassPtr:
1465 case Type::InstKlassPtr: tj = TypeInstKlassPtr::OBJECT; break;
1466 case Type::AnyPtr: tj = TypePtr::BOTTOM; break; // caller checks it
1467 default: ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here(
"/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1467); ::breakpoint(); } while (0)
;
1468 }
1469 break;
1470 case 2: // No collapsing at level 2; keep all splits
1471 case 3: // No collapsing at level 3; keep all splits
1472 break;
1473 default:
1474 Unimplemented()do { (*g_assert_poison) = 'X';; report_unimplemented("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1474); ::breakpoint(); } while (0)
;
1475 }
1476
1477 offset = tj->offset();
1478 assert( offset != Type::OffsetTop, "Offset has fallen from constant" )do { if (!(offset != Type::OffsetTop)) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1478, "assert(" "offset != Type::OffsetTop" ") failed", "Offset has fallen from constant"
); ::breakpoint(); } } while (0)
;
1479
1480 assert( (offset != Type::OffsetBot && tj->base() != Type::AryPtr) ||do { if (!((offset != Type::OffsetBot && tj->base(
) != Type::AryPtr) || (offset == Type::OffsetBot && tj
->base() == Type::AryPtr) || (offset == Type::OffsetBot &&
tj == TypeOopPtr::BOTTOM) || (offset == Type::OffsetBot &&
tj == TypePtr::BOTTOM) || (offset == oopDesc::mark_offset_in_bytes
() && tj->base() == Type::AryPtr) || (offset == oopDesc
::klass_offset_in_bytes() && tj->base() == Type::AryPtr
) || (offset == arrayOopDesc::length_offset_in_bytes() &&
tj->base() == Type::AryPtr))) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1487, "assert(" "(offset != Type::OffsetBot && tj->base() != Type::AryPtr) || (offset == Type::OffsetBot && tj->base() == Type::AryPtr) || (offset == Type::OffsetBot && tj == TypeOopPtr::BOTTOM) || (offset == Type::OffsetBot && tj == TypePtr::BOTTOM) || (offset == oopDesc::mark_offset_in_bytes() && tj->base() == Type::AryPtr) || (offset == oopDesc::klass_offset_in_bytes() && tj->base() == Type::AryPtr) || (offset == arrayOopDesc::length_offset_in_bytes() && tj->base() == Type::AryPtr)"
") failed", "For oops, klasses, raw offset must be constant; for arrays the offset is never known"
); ::breakpoint(); } } while (0)
1481 (offset == Type::OffsetBot && tj->base() == Type::AryPtr) ||do { if (!((offset != Type::OffsetBot && tj->base(
) != Type::AryPtr) || (offset == Type::OffsetBot && tj
->base() == Type::AryPtr) || (offset == Type::OffsetBot &&
tj == TypeOopPtr::BOTTOM) || (offset == Type::OffsetBot &&
tj == TypePtr::BOTTOM) || (offset == oopDesc::mark_offset_in_bytes
() && tj->base() == Type::AryPtr) || (offset == oopDesc
::klass_offset_in_bytes() && tj->base() == Type::AryPtr
) || (offset == arrayOopDesc::length_offset_in_bytes() &&
tj->base() == Type::AryPtr))) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1487, "assert(" "(offset != Type::OffsetBot && tj->base() != Type::AryPtr) || (offset == Type::OffsetBot && tj->base() == Type::AryPtr) || (offset == Type::OffsetBot && tj == TypeOopPtr::BOTTOM) || (offset == Type::OffsetBot && tj == TypePtr::BOTTOM) || (offset == oopDesc::mark_offset_in_bytes() && tj->base() == Type::AryPtr) || (offset == oopDesc::klass_offset_in_bytes() && tj->base() == Type::AryPtr) || (offset == arrayOopDesc::length_offset_in_bytes() && tj->base() == Type::AryPtr)"
") failed", "For oops, klasses, raw offset must be constant; for arrays the offset is never known"
); ::breakpoint(); } } while (0)
1482 (offset == Type::OffsetBot && tj == TypeOopPtr::BOTTOM) ||do { if (!((offset != Type::OffsetBot && tj->base(
) != Type::AryPtr) || (offset == Type::OffsetBot && tj
->base() == Type::AryPtr) || (offset == Type::OffsetBot &&
tj == TypeOopPtr::BOTTOM) || (offset == Type::OffsetBot &&
tj == TypePtr::BOTTOM) || (offset == oopDesc::mark_offset_in_bytes
() && tj->base() == Type::AryPtr) || (offset == oopDesc
::klass_offset_in_bytes() && tj->base() == Type::AryPtr
) || (offset == arrayOopDesc::length_offset_in_bytes() &&
tj->base() == Type::AryPtr))) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1487, "assert(" "(offset != Type::OffsetBot && tj->base() != Type::AryPtr) || (offset == Type::OffsetBot && tj->base() == Type::AryPtr) || (offset == Type::OffsetBot && tj == TypeOopPtr::BOTTOM) || (offset == Type::OffsetBot && tj == TypePtr::BOTTOM) || (offset == oopDesc::mark_offset_in_bytes() && tj->base() == Type::AryPtr) || (offset == oopDesc::klass_offset_in_bytes() && tj->base() == Type::AryPtr) || (offset == arrayOopDesc::length_offset_in_bytes() && tj->base() == Type::AryPtr)"
") failed", "For oops, klasses, raw offset must be constant; for arrays the offset is never known"
); ::breakpoint(); } } while (0)
1483 (offset == Type::OffsetBot && tj == TypePtr::BOTTOM) ||do { if (!((offset != Type::OffsetBot && tj->base(
) != Type::AryPtr) || (offset == Type::OffsetBot && tj
->base() == Type::AryPtr) || (offset == Type::OffsetBot &&
tj == TypeOopPtr::BOTTOM) || (offset == Type::OffsetBot &&
tj == TypePtr::BOTTOM) || (offset == oopDesc::mark_offset_in_bytes
() && tj->base() == Type::AryPtr) || (offset == oopDesc
::klass_offset_in_bytes() && tj->base() == Type::AryPtr
) || (offset == arrayOopDesc::length_offset_in_bytes() &&
tj->base() == Type::AryPtr))) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1487, "assert(" "(offset != Type::OffsetBot && tj->base() != Type::AryPtr) || (offset == Type::OffsetBot && tj->base() == Type::AryPtr) || (offset == Type::OffsetBot && tj == TypeOopPtr::BOTTOM) || (offset == Type::OffsetBot && tj == TypePtr::BOTTOM) || (offset == oopDesc::mark_offset_in_bytes() && tj->base() == Type::AryPtr) || (offset == oopDesc::klass_offset_in_bytes() && tj->base() == Type::AryPtr) || (offset == arrayOopDesc::length_offset_in_bytes() && tj->base() == Type::AryPtr)"
") failed", "For oops, klasses, raw offset must be constant; for arrays the offset is never known"
); ::breakpoint(); } } while (0)
1484 (offset == oopDesc::mark_offset_in_bytes() && tj->base() == Type::AryPtr) ||do { if (!((offset != Type::OffsetBot && tj->base(
) != Type::AryPtr) || (offset == Type::OffsetBot && tj
->base() == Type::AryPtr) || (offset == Type::OffsetBot &&
tj == TypeOopPtr::BOTTOM) || (offset == Type::OffsetBot &&
tj == TypePtr::BOTTOM) || (offset == oopDesc::mark_offset_in_bytes
() && tj->base() == Type::AryPtr) || (offset == oopDesc
::klass_offset_in_bytes() && tj->base() == Type::AryPtr
) || (offset == arrayOopDesc::length_offset_in_bytes() &&
tj->base() == Type::AryPtr))) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1487, "assert(" "(offset != Type::OffsetBot && tj->base() != Type::AryPtr) || (offset == Type::OffsetBot && tj->base() == Type::AryPtr) || (offset == Type::OffsetBot && tj == TypeOopPtr::BOTTOM) || (offset == Type::OffsetBot && tj == TypePtr::BOTTOM) || (offset == oopDesc::mark_offset_in_bytes() && tj->base() == Type::AryPtr) || (offset == oopDesc::klass_offset_in_bytes() && tj->base() == Type::AryPtr) || (offset == arrayOopDesc::length_offset_in_bytes() && tj->base() == Type::AryPtr)"
") failed", "For oops, klasses, raw offset must be constant; for arrays the offset is never known"
); ::breakpoint(); } } while (0)
1485 (offset == oopDesc::klass_offset_in_bytes() && tj->base() == Type::AryPtr) ||do { if (!((offset != Type::OffsetBot && tj->base(
) != Type::AryPtr) || (offset == Type::OffsetBot && tj
->base() == Type::AryPtr) || (offset == Type::OffsetBot &&
tj == TypeOopPtr::BOTTOM) || (offset == Type::OffsetBot &&
tj == TypePtr::BOTTOM) || (offset == oopDesc::mark_offset_in_bytes
() && tj->base() == Type::AryPtr) || (offset == oopDesc
::klass_offset_in_bytes() && tj->base() == Type::AryPtr
) || (offset == arrayOopDesc::length_offset_in_bytes() &&
tj->base() == Type::AryPtr))) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1487, "assert(" "(offset != Type::OffsetBot && tj->base() != Type::AryPtr) || (offset == Type::OffsetBot && tj->base() == Type::AryPtr) || (offset == Type::OffsetBot && tj == TypeOopPtr::BOTTOM) || (offset == Type::OffsetBot && tj == TypePtr::BOTTOM) || (offset == oopDesc::mark_offset_in_bytes() && tj->base() == Type::AryPtr) || (offset == oopDesc::klass_offset_in_bytes() && tj->base() == Type::AryPtr) || (offset == arrayOopDesc::length_offset_in_bytes() && tj->base() == Type::AryPtr)"
") failed", "For oops, klasses, raw offset must be constant; for arrays the offset is never known"
); ::breakpoint(); } } while (0)
1486 (offset == arrayOopDesc::length_offset_in_bytes() && tj->base() == Type::AryPtr),do { if (!((offset != Type::OffsetBot && tj->base(
) != Type::AryPtr) || (offset == Type::OffsetBot && tj
->base() == Type::AryPtr) || (offset == Type::OffsetBot &&
tj == TypeOopPtr::BOTTOM) || (offset == Type::OffsetBot &&
tj == TypePtr::BOTTOM) || (offset == oopDesc::mark_offset_in_bytes
() && tj->base() == Type::AryPtr) || (offset == oopDesc
::klass_offset_in_bytes() && tj->base() == Type::AryPtr
) || (offset == arrayOopDesc::length_offset_in_bytes() &&
tj->base() == Type::AryPtr))) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1487, "assert(" "(offset != Type::OffsetBot && tj->base() != Type::AryPtr) || (offset == Type::OffsetBot && tj->base() == Type::AryPtr) || (offset == Type::OffsetBot && tj == TypeOopPtr::BOTTOM) || (offset == Type::OffsetBot && tj == TypePtr::BOTTOM) || (offset == oopDesc::mark_offset_in_bytes() && tj->base() == Type::AryPtr) || (offset == oopDesc::klass_offset_in_bytes() && tj->base() == Type::AryPtr) || (offset == arrayOopDesc::length_offset_in_bytes() && tj->base() == Type::AryPtr)"
") failed", "For oops, klasses, raw offset must be constant; for arrays the offset is never known"
); ::breakpoint(); } } while (0)
1487 "For oops, klasses, raw offset must be constant; for arrays the offset is never known" )do { if (!((offset != Type::OffsetBot && tj->base(
) != Type::AryPtr) || (offset == Type::OffsetBot && tj
->base() == Type::AryPtr) || (offset == Type::OffsetBot &&
tj == TypeOopPtr::BOTTOM) || (offset == Type::OffsetBot &&
tj == TypePtr::BOTTOM) || (offset == oopDesc::mark_offset_in_bytes
() && tj->base() == Type::AryPtr) || (offset == oopDesc
::klass_offset_in_bytes() && tj->base() == Type::AryPtr
) || (offset == arrayOopDesc::length_offset_in_bytes() &&
tj->base() == Type::AryPtr))) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1487, "assert(" "(offset != Type::OffsetBot && tj->base() != Type::AryPtr) || (offset == Type::OffsetBot && tj->base() == Type::AryPtr) || (offset == Type::OffsetBot && tj == TypeOopPtr::BOTTOM) || (offset == Type::OffsetBot && tj == TypePtr::BOTTOM) || (offset == oopDesc::mark_offset_in_bytes() && tj->base() == Type::AryPtr) || (offset == oopDesc::klass_offset_in_bytes() && tj->base() == Type::AryPtr) || (offset == arrayOopDesc::length_offset_in_bytes() && tj->base() == Type::AryPtr)"
") failed", "For oops, klasses, raw offset must be constant; for arrays the offset is never known"
); ::breakpoint(); } } while (0)
;
1488 assert( tj->ptr() != TypePtr::TopPTR &&do { if (!(tj->ptr() != TypePtr::TopPTR && tj->
ptr() != TypePtr::AnyNull && tj->ptr() != TypePtr::
Null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1490, "assert(" "tj->ptr() != TypePtr::TopPTR && tj->ptr() != TypePtr::AnyNull && tj->ptr() != TypePtr::Null"
") failed", "No imprecise addresses"); ::breakpoint(); } } while
(0)
1489 tj->ptr() != TypePtr::AnyNull &&do { if (!(tj->ptr() != TypePtr::TopPTR && tj->
ptr() != TypePtr::AnyNull && tj->ptr() != TypePtr::
Null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1490, "assert(" "tj->ptr() != TypePtr::TopPTR && tj->ptr() != TypePtr::AnyNull && tj->ptr() != TypePtr::Null"
") failed", "No imprecise addresses"); ::breakpoint(); } } while
(0)
1490 tj->ptr() != TypePtr::Null, "No imprecise addresses" )do { if (!(tj->ptr() != TypePtr::TopPTR && tj->
ptr() != TypePtr::AnyNull && tj->ptr() != TypePtr::
Null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1490, "assert(" "tj->ptr() != TypePtr::TopPTR && tj->ptr() != TypePtr::AnyNull && tj->ptr() != TypePtr::Null"
") failed", "No imprecise addresses"); ::breakpoint(); } } while
(0)
;
1491// assert( tj->ptr() != TypePtr::Constant ||
1492// tj->base() == Type::RawPtr ||
1493// tj->base() == Type::KlassPtr, "No constant oop addresses" );
1494
1495 return tj;
1496}
1497
1498void Compile::AliasType::Init(int i, const TypePtr* at) {
1499 assert(AliasIdxTop <= i && i < Compile::current()->_max_alias_types, "Invalid alias index")do { if (!(AliasIdxTop <= i && i < Compile::current
()->_max_alias_types)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1499, "assert(" "AliasIdxTop <= i && i < Compile::current()->_max_alias_types"
") failed", "Invalid alias index"); ::breakpoint(); } } while
(0)
;
1500 _index = i;
1501 _adr_type = at;
1502 _field = NULL__null;
1503 _element = NULL__null;
1504 _is_rewritable = true; // default
1505 const TypeOopPtr *atoop = (at != NULL__null) ? at->isa_oopptr() : NULL__null;
1506 if (atoop != NULL__null && atoop->is_known_instance()) {
1507 const TypeOopPtr *gt = atoop->cast_to_instance_id(TypeOopPtr::InstanceBot);
1508 _general_index = Compile::current()->get_alias_index(gt);
1509 } else {
1510 _general_index = 0;
1511 }
1512}
1513
1514BasicType Compile::AliasType::basic_type() const {
1515 if (element() != NULL__null) {
1516 const Type* element = adr_type()->is_aryptr()->elem();
1517 return element->isa_narrowoop() ? T_OBJECT : element->array_element_basic_type();
1518 } if (field() != NULL__null) {
1519 return field()->layout_type();
1520 } else {
1521 return T_ILLEGAL; // unknown
1522 }
1523}
1524
1525//---------------------------------print_on------------------------------------
1526#ifndef PRODUCT
1527void Compile::AliasType::print_on(outputStream* st) {
1528 if (index() < 10)
1529 st->print("@ <%d> ", index());
1530 else st->print("@ <%d>", index());
1531 st->print(is_rewritable() ? " " : " RO");
1532 int offset = adr_type()->offset();
1533 if (offset == Type::OffsetBot)
1534 st->print(" +any");
1535 else st->print(" +%-3d", offset);
1536 st->print(" in ");
1537 adr_type()->dump_on(st);
1538 const TypeOopPtr* tjp = adr_type()->isa_oopptr();
1539 if (field() != NULL__null && tjp) {
1540 if (tjp->klass() != field()->holder() ||
1541 tjp->offset() != field()->offset_in_bytes()) {
1542 st->print(" != ");
1543 field()->print();
1544 st->print(" ***");
1545 }
1546 }
1547}
1548
1549void print_alias_types() {
1550 Compile* C = Compile::current();
1551 tty->print_cr("--- Alias types, AliasIdxBot .. %d", C->num_alias_types()-1);
1552 for (int idx = Compile::AliasIdxBot; idx < C->num_alias_types(); idx++) {
1553 C->alias_type(idx)->print_on(tty);
1554 tty->cr();
1555 }
1556}
1557#endif
1558
1559
1560//----------------------------probe_alias_cache--------------------------------
1561Compile::AliasCacheEntry* Compile::probe_alias_cache(const TypePtr* adr_type) {
1562 intptr_t key = (intptr_t) adr_type;
1563 key ^= key >> logAliasCacheSize;
1564 return &_alias_cache[key & right_n_bits(logAliasCacheSize)((((logAliasCacheSize) >= BitsPerWord) ? 0 : (OneBit <<
(logAliasCacheSize))) - 1)
];
1565}
1566
1567
1568//-----------------------------grow_alias_types--------------------------------
1569void Compile::grow_alias_types() {
1570 const int old_ats = _max_alias_types; // how many before?
1571 const int new_ats = old_ats; // how many more?
1572 const int grow_ats = old_ats+new_ats; // how many now?
1573 _max_alias_types = grow_ats;
1574 _alias_types = REALLOC_ARENA_ARRAY(comp_arena(), AliasType*, _alias_types, old_ats, grow_ats)(AliasType**) (comp_arena())->Arealloc((char*)(_alias_types
), (old_ats) * sizeof(AliasType*), (grow_ats) * sizeof(AliasType
*) )
;
1575 AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType, new_ats)(AliasType*) (comp_arena())->Amalloc((new_ats) * sizeof(AliasType
))
;
1576 Copy::zero_to_bytes(ats, sizeof(AliasType)*new_ats);
1577 for (int i = 0; i < new_ats; i++) _alias_types[old_ats+i] = &ats[i];
1578}
1579
1580
1581//--------------------------------find_alias_type------------------------------
1582Compile::AliasType* Compile::find_alias_type(const TypePtr* adr_type, bool no_create, ciField* original_field) {
1583 if (_AliasLevel == 0)
1584 return alias_type(AliasIdxBot);
1585
1586 AliasCacheEntry* ace = probe_alias_cache(adr_type);
1587 if (ace->_adr_type == adr_type) {
1588 return alias_type(ace->_index);
1589 }
1590
1591 // Handle special cases.
1592 if (adr_type == NULL__null) return alias_type(AliasIdxTop);
1593 if (adr_type == TypePtr::BOTTOM) return alias_type(AliasIdxBot);
1594
1595 // Do it the slow way.
1596 const TypePtr* flat = flatten_alias_type(adr_type);
1597
1598#ifdef ASSERT1
1599 {
1600 ResourceMark rm;
1601 assert(flat == flatten_alias_type(flat), "not idempotent: adr_type = %s; flat = %s => %s",do { if (!(flat == flatten_alias_type(flat))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1602, "assert(" "flat == flatten_alias_type(flat)" ") failed"
, "not idempotent: adr_type = %s; flat = %s => %s", Type::
str(adr_type), Type::str(flat), Type::str(flatten_alias_type(
flat))); ::breakpoint(); } } while (0)
1602 Type::str(adr_type), Type::str(flat), Type::str(flatten_alias_type(flat)))do { if (!(flat == flatten_alias_type(flat))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1602, "assert(" "flat == flatten_alias_type(flat)" ") failed"
, "not idempotent: adr_type = %s; flat = %s => %s", Type::
str(adr_type), Type::str(flat), Type::str(flatten_alias_type(
flat))); ::breakpoint(); } } while (0)
;
1603 assert(flat != TypePtr::BOTTOM, "cannot alias-analyze an untyped ptr: adr_type = %s",do { if (!(flat != TypePtr::BOTTOM)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1604, "assert(" "flat != TypePtr::BOTTOM" ") failed", "cannot alias-analyze an untyped ptr: adr_type = %s"
, Type::str(adr_type)); ::breakpoint(); } } while (0)
1604 Type::str(adr_type))do { if (!(flat != TypePtr::BOTTOM)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1604, "assert(" "flat != TypePtr::BOTTOM" ") failed", "cannot alias-analyze an untyped ptr: adr_type = %s"
, Type::str(adr_type)); ::breakpoint(); } } while (0)
;
1605 if (flat->isa_oopptr() && !flat->isa_klassptr()) {
1606 const TypeOopPtr* foop = flat->is_oopptr();
1607 // Scalarizable allocations have exact klass always.
1608 bool exact = !foop->klass_is_exact() || foop->is_known_instance();
1609 const TypePtr* xoop = foop->cast_to_exactness(exact)->is_ptr();
1610 assert(foop == flatten_alias_type(xoop), "exactness must not affect alias type: foop = %s; xoop = %s",do { if (!(foop == flatten_alias_type(xoop))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1611, "assert(" "foop == flatten_alias_type(xoop)" ") failed"
, "exactness must not affect alias type: foop = %s; xoop = %s"
, Type::str(foop), Type::str(xoop)); ::breakpoint(); } } while
(0)
1611 Type::str(foop), Type::str(xoop))do { if (!(foop == flatten_alias_type(xoop))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1611, "assert(" "foop == flatten_alias_type(xoop)" ") failed"
, "exactness must not affect alias type: foop = %s; xoop = %s"
, Type::str(foop), Type::str(xoop)); ::breakpoint(); } } while
(0)
;
1612 }
1613 }
1614#endif
1615
1616 int idx = AliasIdxTop;
1617 for (int i = 0; i < num_alias_types(); i++) {
1618 if (alias_type(i)->adr_type() == flat) {
1619 idx = i;
1620 break;
1621 }
1622 }
1623
1624 if (idx == AliasIdxTop) {
1625 if (no_create) return NULL__null;
1626 // Grow the array if necessary.
1627 if (_num_alias_types == _max_alias_types) grow_alias_types();
1628 // Add a new alias type.
1629 idx = _num_alias_types++;
1630 _alias_types[idx]->Init(idx, flat);
1631 if (flat == TypeInstPtr::KLASS) alias_type(idx)->set_rewritable(false);
1632 if (flat == TypeAryPtr::RANGE) alias_type(idx)->set_rewritable(false);
1633 if (flat->isa_instptr()) {
1634 if (flat->offset() == java_lang_Class::klass_offset()
1635 && flat->is_instptr()->klass() == env()->Class_klass())
1636 alias_type(idx)->set_rewritable(false);
1637 }
1638 if (flat->isa_aryptr()) {
1639#ifdef ASSERT1
1640 const int header_size_min = arrayOopDesc::base_offset_in_bytes(T_BYTE);
1641 // (T_BYTE has the weakest alignment and size restrictions...)
1642 assert(flat->offset() < header_size_min, "array body reference must be OffsetBot")do { if (!(flat->offset() < header_size_min)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1642, "assert(" "flat->offset() < header_size_min" ") failed"
, "array body reference must be OffsetBot"); ::breakpoint(); }
} while (0)
;
1643#endif
1644 if (flat->offset() == TypePtr::OffsetBot) {
1645 alias_type(idx)->set_element(flat->is_aryptr()->elem());
1646 }
1647 }
1648 if (flat->isa_klassptr()) {
1649 if (flat->offset() == in_bytes(Klass::super_check_offset_offset()))
1650 alias_type(idx)->set_rewritable(false);
1651 if (flat->offset() == in_bytes(Klass::modifier_flags_offset()))
1652 alias_type(idx)->set_rewritable(false);
1653 if (flat->offset() == in_bytes(Klass::access_flags_offset()))
1654 alias_type(idx)->set_rewritable(false);
1655 if (flat->offset() == in_bytes(Klass::java_mirror_offset()))
1656 alias_type(idx)->set_rewritable(false);
1657 if (flat->offset() == in_bytes(Klass::secondary_super_cache_offset()))
1658 alias_type(idx)->set_rewritable(false);
1659 }
1660 // %%% (We would like to finalize JavaThread::threadObj_offset(),
1661 // but the base pointer type is not distinctive enough to identify
1662 // references into JavaThread.)
1663
1664 // Check for final fields.
1665 const TypeInstPtr* tinst = flat->isa_instptr();
1666 if (tinst && tinst->offset() >= instanceOopDesc::base_offset_in_bytes()) {
1667 ciField* field;
1668 if (tinst->const_oop() != NULL__null &&
1669 tinst->klass() == ciEnv::current()->Class_klass() &&
1670 tinst->offset() >= (tinst->klass()->as_instance_klass()->layout_helper_size_in_bytes())) {
1671 // static field
1672 ciInstanceKlass* k = tinst->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
1673 field = k->get_field_by_offset(tinst->offset(), true);
1674 } else {
1675 ciInstanceKlass *k = tinst->klass()->as_instance_klass();
1676 field = k->get_field_by_offset(tinst->offset(), false);
1677 }
1678 assert(field == NULL ||do { if (!(field == __null || original_field == __null || (field
->holder() == original_field->holder() && field
->offset() == original_field->offset() && field
->is_static() == original_field->is_static()))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1682, "assert(" "field == __null || original_field == __null || (field->holder() == original_field->holder() && field->offset() == original_field->offset() && field->is_static() == original_field->is_static())"
") failed", "wrong field?"); ::breakpoint(); } } while (0)
1679 original_field == NULL ||do { if (!(field == __null || original_field == __null || (field
->holder() == original_field->holder() && field
->offset() == original_field->offset() && field
->is_static() == original_field->is_static()))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1682, "assert(" "field == __null || original_field == __null || (field->holder() == original_field->holder() && field->offset() == original_field->offset() && field->is_static() == original_field->is_static())"
") failed", "wrong field?"); ::breakpoint(); } } while (0)
1680 (field->holder() == original_field->holder() &&do { if (!(field == __null || original_field == __null || (field
->holder() == original_field->holder() && field
->offset() == original_field->offset() && field
->is_static() == original_field->is_static()))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1682, "assert(" "field == __null || original_field == __null || (field->holder() == original_field->holder() && field->offset() == original_field->offset() && field->is_static() == original_field->is_static())"
") failed", "wrong field?"); ::breakpoint(); } } while (0)
1681 field->offset() == original_field->offset() &&do { if (!(field == __null || original_field == __null || (field
->holder() == original_field->holder() && field
->offset() == original_field->offset() && field
->is_static() == original_field->is_static()))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1682, "assert(" "field == __null || original_field == __null || (field->holder() == original_field->holder() && field->offset() == original_field->offset() && field->is_static() == original_field->is_static())"
") failed", "wrong field?"); ::breakpoint(); } } while (0)
1682 field->is_static() == original_field->is_static()), "wrong field?")do { if (!(field == __null || original_field == __null || (field
->holder() == original_field->holder() && field
->offset() == original_field->offset() && field
->is_static() == original_field->is_static()))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1682, "assert(" "field == __null || original_field == __null || (field->holder() == original_field->holder() && field->offset() == original_field->offset() && field->is_static() == original_field->is_static())"
") failed", "wrong field?"); ::breakpoint(); } } while (0)
;
1683 // Set field() and is_rewritable() attributes.
1684 if (field != NULL__null) alias_type(idx)->set_field(field);
1685 }
1686 }
1687
1688 // Fill the cache for next time.
1689 ace->_adr_type = adr_type;
1690 ace->_index = idx;
1691 assert(alias_type(adr_type) == alias_type(idx), "type must be installed")do { if (!(alias_type(adr_type) == alias_type(idx))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1691, "assert(" "alias_type(adr_type) == alias_type(idx)" ") failed"
, "type must be installed"); ::breakpoint(); } } while (0)
;
1692
1693 // Might as well try to fill the cache for the flattened version, too.
1694 AliasCacheEntry* face = probe_alias_cache(flat);
1695 if (face->_adr_type == NULL__null) {
1696 face->_adr_type = flat;
1697 face->_index = idx;
1698 assert(alias_type(flat) == alias_type(idx), "flat type must work too")do { if (!(alias_type(flat) == alias_type(idx))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1698, "assert(" "alias_type(flat) == alias_type(idx)" ") failed"
, "flat type must work too"); ::breakpoint(); } } while (0)
;
1699 }
1700
1701 return alias_type(idx);
1702}
1703
1704
1705Compile::AliasType* Compile::alias_type(ciField* field) {
1706 const TypeOopPtr* t;
1707 if (field->is_static())
1708 t = TypeInstPtr::make(field->holder()->java_mirror());
1709 else
1710 t = TypeOopPtr::make_from_klass_raw(field->holder());
1711 AliasType* atp = alias_type(t->add_offset(field->offset_in_bytes()), field);
1712 assert((field->is_final() || field->is_stable()) == !atp->is_rewritable(), "must get the rewritable bits correct")do { if (!((field->is_final() || field->is_stable()) ==
!atp->is_rewritable())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1712, "assert(" "(field->is_final() || field->is_stable()) == !atp->is_rewritable()"
") failed", "must get the rewritable bits correct"); ::breakpoint
(); } } while (0)
;
1713 return atp;
1714}
1715
1716
1717//------------------------------have_alias_type--------------------------------
1718bool Compile::have_alias_type(const TypePtr* adr_type) {
1719 AliasCacheEntry* ace = probe_alias_cache(adr_type);
1720 if (ace->_adr_type == adr_type) {
1721 return true;
1722 }
1723
1724 // Handle special cases.
1725 if (adr_type == NULL__null) return true;
1726 if (adr_type == TypePtr::BOTTOM) return true;
1727
1728 return find_alias_type(adr_type, true, NULL__null) != NULL__null;
1729}
1730
1731//-----------------------------must_alias--------------------------------------
1732// True if all values of the given address type are in the given alias category.
1733bool Compile::must_alias(const TypePtr* adr_type, int alias_idx) {
1734 if (alias_idx == AliasIdxBot) return true; // the universal category
1735 if (adr_type == NULL__null) return true; // NULL serves as TypePtr::TOP
1736 if (alias_idx == AliasIdxTop) return false; // the empty category
1737 if (adr_type->base() == Type::AnyPtr) return false; // TypePtr::BOTTOM or its twins
1738
1739 // the only remaining possible overlap is identity
1740 int adr_idx = get_alias_index(adr_type);
1741 assert(adr_idx != AliasIdxBot && adr_idx != AliasIdxTop, "")do { if (!(adr_idx != AliasIdxBot && adr_idx != AliasIdxTop
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1741, "assert(" "adr_idx != AliasIdxBot && adr_idx != AliasIdxTop"
") failed", ""); ::breakpoint(); } } while (0)
;
1742 assert(adr_idx == alias_idx ||do { if (!(adr_idx == alias_idx || (alias_type(alias_idx)->
adr_type() != TypeOopPtr::BOTTOM && adr_type != TypeOopPtr
::BOTTOM))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1745, "assert(" "adr_idx == alias_idx || (alias_type(alias_idx)->adr_type() != TypeOopPtr::BOTTOM && adr_type != TypeOopPtr::BOTTOM)"
") failed", "should not be testing for overlap with an unsafe pointer"
); ::breakpoint(); } } while (0)
1743 (alias_type(alias_idx)->adr_type() != TypeOopPtr::BOTTOMdo { if (!(adr_idx == alias_idx || (alias_type(alias_idx)->
adr_type() != TypeOopPtr::BOTTOM && adr_type != TypeOopPtr
::BOTTOM))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1745, "assert(" "adr_idx == alias_idx || (alias_type(alias_idx)->adr_type() != TypeOopPtr::BOTTOM && adr_type != TypeOopPtr::BOTTOM)"
") failed", "should not be testing for overlap with an unsafe pointer"
); ::breakpoint(); } } while (0)
1744 && adr_type != TypeOopPtr::BOTTOM),do { if (!(adr_idx == alias_idx || (alias_type(alias_idx)->
adr_type() != TypeOopPtr::BOTTOM && adr_type != TypeOopPtr
::BOTTOM))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1745, "assert(" "adr_idx == alias_idx || (alias_type(alias_idx)->adr_type() != TypeOopPtr::BOTTOM && adr_type != TypeOopPtr::BOTTOM)"
") failed", "should not be testing for overlap with an unsafe pointer"
); ::breakpoint(); } } while (0)
1745 "should not be testing for overlap with an unsafe pointer")do { if (!(adr_idx == alias_idx || (alias_type(alias_idx)->
adr_type() != TypeOopPtr::BOTTOM && adr_type != TypeOopPtr
::BOTTOM))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1745, "assert(" "adr_idx == alias_idx || (alias_type(alias_idx)->adr_type() != TypeOopPtr::BOTTOM && adr_type != TypeOopPtr::BOTTOM)"
") failed", "should not be testing for overlap with an unsafe pointer"
); ::breakpoint(); } } while (0)
;
1746 return adr_idx == alias_idx;
1747}
1748
1749//------------------------------can_alias--------------------------------------
1750// True if any values of the given address type are in the given alias category.
1751bool Compile::can_alias(const TypePtr* adr_type, int alias_idx) {
1752 if (alias_idx == AliasIdxTop) return false; // the empty category
1753 if (adr_type == NULL__null) return false; // NULL serves as TypePtr::TOP
1754 // Known instance doesn't alias with bottom memory
1755 if (alias_idx == AliasIdxBot) return !adr_type->is_known_instance(); // the universal category
1756 if (adr_type->base() == Type::AnyPtr) return !C->get_adr_type(alias_idx)->is_known_instance(); // TypePtr::BOTTOM or its twins
1757
1758 // the only remaining possible overlap is identity
1759 int adr_idx = get_alias_index(adr_type);
1760 assert(adr_idx != AliasIdxBot && adr_idx != AliasIdxTop, "")do { if (!(adr_idx != AliasIdxBot && adr_idx != AliasIdxTop
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1760, "assert(" "adr_idx != AliasIdxBot && adr_idx != AliasIdxTop"
") failed", ""); ::breakpoint(); } } while (0)
;
1761 return adr_idx == alias_idx;
1762}
1763
1764//---------------------cleanup_loop_predicates-----------------------
1765// Remove the opaque nodes that protect the predicates so that all unused
1766// checks and uncommon_traps will be eliminated from the ideal graph
1767void Compile::cleanup_loop_predicates(PhaseIterGVN &igvn) {
1768 if (predicate_count()==0) return;
1769 for (int i = predicate_count(); i > 0; i--) {
1770 Node * n = predicate_opaque1_node(i-1);
1771 assert(n->Opcode() == Op_Opaque1, "must be")do { if (!(n->Opcode() == Op_Opaque1)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1771, "assert(" "n->Opcode() == Op_Opaque1" ") failed", "must be"
); ::breakpoint(); } } while (0)
;
1772 igvn.replace_node(n, n->in(1));
1773 }
1774 assert(predicate_count()==0, "should be clean!")do { if (!(predicate_count()==0)) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1774, "assert(" "predicate_count()==0" ") failed", "should be clean!"
); ::breakpoint(); } } while (0)
;
1775}
1776
1777void Compile::record_for_post_loop_opts_igvn(Node* n) {
1778 if (!n->for_post_loop_opts_igvn()) {
1779 assert(!_for_post_loop_igvn.contains(n), "duplicate")do { if (!(!_for_post_loop_igvn.contains(n))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1779, "assert(" "!_for_post_loop_igvn.contains(n)" ") failed"
, "duplicate"); ::breakpoint(); } } while (0)
;
1780 n->add_flag(Node::NodeFlags::Flag_for_post_loop_opts_igvn);
1781 _for_post_loop_igvn.append(n);
1782 }
1783}
1784
1785void Compile::remove_from_post_loop_opts_igvn(Node* n) {
1786 n->remove_flag(Node::NodeFlags::Flag_for_post_loop_opts_igvn);
1787 _for_post_loop_igvn.remove(n);
1788}
1789
1790void Compile::process_for_post_loop_opts_igvn(PhaseIterGVN& igvn) {
1791 // Verify that all previous optimizations produced a valid graph
1792 // at least to this point, even if no loop optimizations were done.
1793 PhaseIdealLoop::verify(igvn);
1794
1795 C->set_post_loop_opts_phase(); // no more loop opts allowed
1796
1797 assert(!C->major_progress(), "not cleared")do { if (!(!C->major_progress())) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1797, "assert(" "!C->major_progress()" ") failed", "not cleared"
); ::breakpoint(); } } while (0)
;
1798
1799 if (_for_post_loop_igvn.length() > 0) {
1800 while (_for_post_loop_igvn.length() > 0) {
1801 Node* n = _for_post_loop_igvn.pop();
1802 n->remove_flag(Node::NodeFlags::Flag_for_post_loop_opts_igvn);
1803 igvn._worklist.push(n);
1804 }
1805 igvn.optimize();
1806 assert(_for_post_loop_igvn.length() == 0, "no more delayed nodes allowed")do { if (!(_for_post_loop_igvn.length() == 0)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1806, "assert(" "_for_post_loop_igvn.length() == 0" ") failed"
, "no more delayed nodes allowed"); ::breakpoint(); } } while
(0)
;
1807
1808 // Sometimes IGVN sets major progress (e.g., when processing loop nodes).
1809 if (C->major_progress()) {
1810 C->clear_major_progress(); // ensure that major progress is now clear
1811 }
1812 }
1813}
1814
1815// StringOpts and late inlining of string methods
1816void Compile::inline_string_calls(bool parse_time) {
1817 {
1818 // remove useless nodes to make the usage analysis simpler
1819 ResourceMark rm;
1820 PhaseRemoveUseless pru(initial_gvn(), for_igvn());
1821 }
1822
1823 {
1824 ResourceMark rm;
1825 print_method(PHASE_BEFORE_STRINGOPTS, 3);
1826 PhaseStringOpts pso(initial_gvn(), for_igvn());
1827 print_method(PHASE_AFTER_STRINGOPTS, 3);
1828 }
1829
1830 // now inline anything that we skipped the first time around
1831 if (!parse_time) {
1832 _late_inlines_pos = _late_inlines.length();
1833 }
1834
1835 while (_string_late_inlines.length() > 0) {
1836 CallGenerator* cg = _string_late_inlines.pop();
1837 cg->do_late_inline();
1838 if (failing()) return;
1839 }
1840 _string_late_inlines.trunc_to(0);
1841}
1842
1843// Late inlining of boxing methods
1844void Compile::inline_boxing_calls(PhaseIterGVN& igvn) {
1845 if (_boxing_late_inlines.length() > 0) {
1846 assert(has_boxed_value(), "inconsistent")do { if (!(has_boxed_value())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1846, "assert(" "has_boxed_value()" ") failed", "inconsistent"
); ::breakpoint(); } } while (0)
;
1847
1848 PhaseGVN* gvn = initial_gvn();
1849 set_inlining_incrementally(true);
1850
1851 assert( igvn._worklist.size() == 0, "should be done with igvn" )do { if (!(igvn._worklist.size() == 0)) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1851, "assert(" "igvn._worklist.size() == 0" ") failed", "should be done with igvn"
); ::breakpoint(); } } while (0)
;
1852 for_igvn()->clear();
1853 gvn->replace_with(&igvn);
1854
1855 _late_inlines_pos = _late_inlines.length();
1856
1857 while (_boxing_late_inlines.length() > 0) {
1858 CallGenerator* cg = _boxing_late_inlines.pop();
1859 cg->do_late_inline();
1860 if (failing()) return;
1861 }
1862 _boxing_late_inlines.trunc_to(0);
1863
1864 inline_incrementally_cleanup(igvn);
1865
1866 set_inlining_incrementally(false);
1867 }
1868}
1869
1870bool Compile::inline_incrementally_one() {
1871 assert(IncrementalInline, "incremental inlining should be on")do { if (!(IncrementalInline)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1871, "assert(" "IncrementalInline" ") failed", "incremental inlining should be on"
); ::breakpoint(); } } while (0)
;
1872
1873 TracePhase tp("incrementalInline_inline", &timers[_t_incrInline_inline]);
1874
1875 set_inlining_progress(false);
1876 set_do_cleanup(false);
1877
1878 for (int i = 0; i < _late_inlines.length(); i++) {
1879 _late_inlines_pos = i+1;
1880 CallGenerator* cg = _late_inlines.at(i);
1881 bool does_dispatch = cg->is_virtual_late_inline() || cg->is_mh_late_inline();
1882 if (inlining_incrementally() || does_dispatch) { // a call can be either inlined or strength-reduced to a direct call
1883 cg->do_late_inline();
1884 assert(_late_inlines.at(i) == cg, "no insertions before current position allowed")do { if (!(_late_inlines.at(i) == cg)) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1884, "assert(" "_late_inlines.at(i) == cg" ") failed", "no insertions before current position allowed"
); ::breakpoint(); } } while (0)
;
1885 if (failing()) {
1886 return false;
1887 } else if (inlining_progress()) {
1888 _late_inlines_pos = i+1; // restore the position in case new elements were inserted
1889 print_method(PHASE_INCREMENTAL_INLINE_STEP, cg->call_node(), 3);
1890 break; // process one call site at a time
1891 }
1892 } else {
1893 // Ignore late inline direct calls when inlining is not allowed.
1894 // They are left in the late inline list when node budget is exhausted until the list is fully drained.
1895 }
1896 }
1897 // Remove processed elements.
1898 _late_inlines.remove_till(_late_inlines_pos);
1899 _late_inlines_pos = 0;
1900
1901 assert(inlining_progress() || _late_inlines.length() == 0, "no progress")do { if (!(inlining_progress() || _late_inlines.length() == 0
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1901, "assert(" "inlining_progress() || _late_inlines.length() == 0"
") failed", "no progress"); ::breakpoint(); } } while (0)
;
1902
1903 bool needs_cleanup = do_cleanup() || over_inlining_cutoff();
1904
1905 set_inlining_progress(false);
1906 set_do_cleanup(false);
1907
1908 bool force_cleanup = directive()->IncrementalInlineForceCleanupOption;
1909 return (_late_inlines.length() > 0) && !needs_cleanup && !force_cleanup;
1910}
1911
1912void Compile::inline_incrementally_cleanup(PhaseIterGVN& igvn) {
1913 {
1914 TracePhase tp("incrementalInline_pru", &timers[_t_incrInline_pru]);
1915 ResourceMark rm;
1916 PhaseRemoveUseless pru(initial_gvn(), for_igvn());
1917 }
1918 {
1919 TracePhase tp("incrementalInline_igvn", &timers[_t_incrInline_igvn]);
1920 igvn = PhaseIterGVN(initial_gvn());
1921 igvn.optimize();
1922 }
1923 print_method(PHASE_INCREMENTAL_INLINE_CLEANUP, 3);
1924}
1925
1926// Perform incremental inlining until bound on number of live nodes is reached
1927void Compile::inline_incrementally(PhaseIterGVN& igvn) {
1928 TracePhase tp("incrementalInline", &timers[_t_incrInline]);
1929
1930 set_inlining_incrementally(true);
1931 uint low_live_nodes = 0;
1932
1933 while (_late_inlines.length() > 0) {
1934 if (live_nodes() > (uint)LiveNodeCountInliningCutoff) {
1935 if (low_live_nodes < (uint)LiveNodeCountInliningCutoff * 8 / 10) {
1936 TracePhase tp("incrementalInline_ideal", &timers[_t_incrInline_ideal]);
1937 // PhaseIdealLoop is expensive so we only try it once we are
1938 // out of live nodes and we only try it again if the previous
1939 // helped got the number of nodes down significantly
1940 PhaseIdealLoop::optimize(igvn, LoopOptsNone);
1941 if (failing()) return;
1942 low_live_nodes = live_nodes();
1943 _major_progress = true;
1944 }
1945
1946 if (live_nodes() > (uint)LiveNodeCountInliningCutoff) {
1947 bool do_print_inlining = print_inlining() || print_intrinsics();
1948 if (do_print_inlining || log() != NULL__null) {
1949 // Print inlining message for candidates that we couldn't inline for lack of space.
1950 for (int i = 0; i < _late_inlines.length(); i++) {
1951 CallGenerator* cg = _late_inlines.at(i);
1952 const char* msg = "live nodes > LiveNodeCountInliningCutoff";
1953 if (do_print_inlining) {
1954 cg->print_inlining_late(msg);
1955 }
1956 log_late_inline_failure(cg, msg);
1957 }
1958 }
1959 break; // finish
1960 }
1961 }
1962
1963 for_igvn()->clear();
1964 initial_gvn()->replace_with(&igvn);
1965
1966 while (inline_incrementally_one()) {
1967 assert(!failing(), "inconsistent")do { if (!(!failing())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1967, "assert(" "!failing()" ") failed", "inconsistent"); ::
breakpoint(); } } while (0)
;
1968 }
1969 if (failing()) return;
1970
1971 inline_incrementally_cleanup(igvn);
1972
1973 print_method(PHASE_INCREMENTAL_INLINE_STEP, 3);
1974
1975 if (failing()) return;
1976
1977 if (_late_inlines.length() == 0) {
1978 break; // no more progress
1979 }
1980 }
1981 assert( igvn._worklist.size() == 0, "should be done with igvn" )do { if (!(igvn._worklist.size() == 0)) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1981, "assert(" "igvn._worklist.size() == 0" ") failed", "should be done with igvn"
); ::breakpoint(); } } while (0)
;
1982
1983 if (_string_late_inlines.length() > 0) {
1984 assert(has_stringbuilder(), "inconsistent")do { if (!(has_stringbuilder())) { (*g_assert_poison) = 'X';;
report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 1984, "assert(" "has_stringbuilder()" ") failed", "inconsistent"
); ::breakpoint(); } } while (0)
;
1985 for_igvn()->clear();
1986 initial_gvn()->replace_with(&igvn);
1987
1988 inline_string_calls(false);
1989
1990 if (failing()) return;
1991
1992 inline_incrementally_cleanup(igvn);
1993 }
1994
1995 set_inlining_incrementally(false);
1996}
1997
1998void Compile::process_late_inline_calls_no_inline(PhaseIterGVN& igvn) {
1999 // "inlining_incrementally() == false" is used to signal that no inlining is allowed
2000 // (see LateInlineVirtualCallGenerator::do_late_inline_check() for details).
2001 // Tracking and verification of modified nodes is disabled by setting "_modified_nodes == NULL"
2002 // as if "inlining_incrementally() == true" were set.
2003 assert(inlining_incrementally() == false, "not allowed")do { if (!(inlining_incrementally() == false)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2003, "assert(" "inlining_incrementally() == false" ") failed"
, "not allowed"); ::breakpoint(); } } while (0)
;
2004 assert(_modified_nodes == NULL, "not allowed")do { if (!(_modified_nodes == __null)) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2004, "assert(" "_modified_nodes == __null" ") failed", "not allowed"
); ::breakpoint(); } } while (0)
;
2005 assert(_late_inlines.length() > 0, "sanity")do { if (!(_late_inlines.length() > 0)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2005, "assert(" "_late_inlines.length() > 0" ") failed",
"sanity"); ::breakpoint(); } } while (0)
;
2006
2007 while (_late_inlines.length() > 0) {
2008 for_igvn()->clear();
2009 initial_gvn()->replace_with(&igvn);
2010
2011 while (inline_incrementally_one()) {
2012 assert(!failing(), "inconsistent")do { if (!(!failing())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2012, "assert(" "!failing()" ") failed", "inconsistent"); ::
breakpoint(); } } while (0)
;
2013 }
2014 if (failing()) return;
2015
2016 inline_incrementally_cleanup(igvn);
2017 }
2018}
2019
2020bool Compile::optimize_loops(PhaseIterGVN& igvn, LoopOptsMode mode) {
2021 if (_loop_opts_cnt > 0) {
2022 debug_only( int cnt = 0; )int cnt = 0;;
2023 while (major_progress() && (_loop_opts_cnt > 0)) {
2024 TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2025 assert( cnt++ < 40, "infinite cycle in loop optimization" )do { if (!(cnt++ < 40)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2025, "assert(" "cnt++ < 40" ") failed", "infinite cycle in loop optimization"
); ::breakpoint(); } } while (0)
;
2026 PhaseIdealLoop::optimize(igvn, mode);
2027 _loop_opts_cnt--;
2028 if (failing()) return false;
2029 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP_ITERATIONS, 2);
2030 }
2031 }
2032 return true;
2033}
2034
2035// Remove edges from "root" to each SafePoint at a backward branch.
2036// They were inserted during parsing (see add_safepoint()) to make
2037// infinite loops without calls or exceptions visible to root, i.e.,
2038// useful.
2039void Compile::remove_root_to_sfpts_edges(PhaseIterGVN& igvn) {
2040 Node *r = root();
2041 if (r != NULL__null) {
2042 for (uint i = r->req(); i < r->len(); ++i) {
2043 Node *n = r->in(i);
2044 if (n != NULL__null && n->is_SafePoint()) {
2045 r->rm_prec(i);
2046 if (n->outcnt() == 0) {
2047 igvn.remove_dead_node(n);
2048 }
2049 --i;
2050 }
2051 }
2052 // Parsing may have added top inputs to the root node (Path
2053 // leading to the Halt node proven dead). Make sure we get a
2054 // chance to clean them up.
2055 igvn._worklist.push(r);
2056 igvn.optimize();
2057 }
2058}
2059
2060//------------------------------Optimize---------------------------------------
2061// Given a graph, optimize it.
2062void Compile::Optimize() {
2063 TracePhase tp("optimizer", &timers[_t_optimizer]);
2064
2065#ifndef PRODUCT
2066 if (env()->break_at_compile()) {
2067 BREAKPOINT::breakpoint();
2068 }
2069
2070#endif
2071
2072 BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2073#ifdef ASSERT1
2074 bs->verify_gc_barriers(this, BarrierSetC2::BeforeOptimize);
2075#endif
2076
2077 ResourceMark rm;
2078
2079 print_inlining_reinit();
2080
2081 NOT_PRODUCT( verify_graph_edges(); )verify_graph_edges();
2082
2083 print_method(PHASE_AFTER_PARSING);
2084
2085 {
2086 // Iterative Global Value Numbering, including ideal transforms
2087 // Initialize IterGVN with types and values from parse-time GVN
2088 PhaseIterGVN igvn(initial_gvn());
2089#ifdef ASSERT1
2090 _modified_nodes = new (comp_arena()) Unique_Node_List(comp_arena());
2091#endif
2092 {
2093 TracePhase tp("iterGVN", &timers[_t_iterGVN]);
2094 igvn.optimize();
2095 }
2096
2097 if (failing()) return;
2098
2099 print_method(PHASE_ITER_GVN1, 2);
2100
2101 inline_incrementally(igvn);
2102
2103 print_method(PHASE_INCREMENTAL_INLINE, 2);
2104
2105 if (failing()) return;
2106
2107 if (eliminate_boxing()) {
2108 // Inline valueOf() methods now.
2109 inline_boxing_calls(igvn);
2110
2111 if (AlwaysIncrementalInline) {
2112 inline_incrementally(igvn);
2113 }
2114
2115 print_method(PHASE_INCREMENTAL_BOXING_INLINE, 2);
2116
2117 if (failing()) return;
2118 }
2119
2120 // Remove the speculative part of types and clean up the graph from
2121 // the extra CastPP nodes whose only purpose is to carry them. Do
2122 // that early so that optimizations are not disrupted by the extra
2123 // CastPP nodes.
2124 remove_speculative_types(igvn);
2125
2126 // No more new expensive nodes will be added to the list from here
2127 // so keep only the actual candidates for optimizations.
2128 cleanup_expensive_nodes(igvn);
2129
2130 assert(EnableVectorSupport || !has_vbox_nodes(), "sanity")do { if (!(EnableVectorSupport || !has_vbox_nodes())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2130, "assert(" "EnableVectorSupport || !has_vbox_nodes()" ") failed"
, "sanity"); ::breakpoint(); } } while (0)
;
2131 if (EnableVectorSupport && has_vbox_nodes()) {
2132 TracePhase tp("", &timers[_t_vector]);
2133 PhaseVector pv(igvn);
2134 pv.optimize_vector_boxes();
2135
2136 print_method(PHASE_ITER_GVN_AFTER_VECTOR, 2);
2137 }
2138 assert(!has_vbox_nodes(), "sanity")do { if (!(!has_vbox_nodes())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2138, "assert(" "!has_vbox_nodes()" ") failed", "sanity"); ::
breakpoint(); } } while (0)
;
2139
2140 if (!failing() && RenumberLiveNodes && live_nodes() + NodeLimitFudgeFactor < unique()) {
2141 Compile::TracePhase tp("", &timers[_t_renumberLive]);
2142 initial_gvn()->replace_with(&igvn);
2143 Unique_Node_List* old_worklist = for_igvn();
2144 old_worklist->clear();
2145 Unique_Node_List new_worklist(C->comp_arena());
2146 {
2147 ResourceMark rm;
2148 PhaseRenumberLive prl = PhaseRenumberLive(initial_gvn(), for_igvn(), &new_worklist);
2149 }
2150 Unique_Node_List* save_for_igvn = for_igvn();
Value stored to 'save_for_igvn' during its initialization is never read
2151 set_for_igvn(&new_worklist);
2152 igvn = PhaseIterGVN(initial_gvn());
2153 igvn.optimize();
2154 set_for_igvn(old_worklist); // new_worklist is dead beyond this point
2155 }
2156
2157 // Now that all inlining is over and no PhaseRemoveUseless will run, cut edge from root to loop
2158 // safepoints
2159 remove_root_to_sfpts_edges(igvn);
2160
2161 // Perform escape analysis
2162 if (do_escape_analysis() && ConnectionGraph::has_candidates(this)) {
2163 if (has_loops()) {
2164 // Cleanup graph (remove dead nodes).
2165 TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2166 PhaseIdealLoop::optimize(igvn, LoopOptsMaxUnroll);
2167 if (major_progress()) print_method(PHASE_PHASEIDEAL_BEFORE_EA, 2);
2168 if (failing()) return;
2169 }
2170 bool progress;
2171 do {
2172 ConnectionGraph::do_analysis(this, &igvn);
2173
2174 if (failing()) return;
2175
2176 int mcount = macro_count(); // Record number of allocations and locks before IGVN
2177
2178 // Optimize out fields loads from scalar replaceable allocations.
2179 igvn.optimize();
2180 print_method(PHASE_ITER_GVN_AFTER_EA, 2);
2181
2182 if (failing()) return;
2183
2184 if (congraph() != NULL__null && macro_count() > 0) {
2185 TracePhase tp("macroEliminate", &timers[_t_macroEliminate]);
2186 PhaseMacroExpand mexp(igvn);
2187 mexp.eliminate_macro_nodes();
2188 igvn.set_delay_transform(false);
2189
2190 igvn.optimize();
2191 print_method(PHASE_ITER_GVN_AFTER_ELIMINATION, 2);
2192
2193 if (failing()) return;
2194 }
2195 progress = do_iterative_escape_analysis() &&
2196 (macro_count() < mcount) &&
2197 ConnectionGraph::has_candidates(this);
2198 // Try again if candidates exist and made progress
2199 // by removing some allocations and/or locks.
2200 } while (progress);
2201 }
2202
2203 // Loop transforms on the ideal graph. Range Check Elimination,
2204 // peeling, unrolling, etc.
2205
2206 // Set loop opts counter
2207 if((_loop_opts_cnt > 0) && (has_loops() || has_split_ifs())) {
2208 {
2209 TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2210 PhaseIdealLoop::optimize(igvn, LoopOptsDefault);
2211 _loop_opts_cnt--;
2212 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP1, 2);
2213 if (failing()) return;
2214 }
2215 // Loop opts pass if partial peeling occurred in previous pass
2216 if(PartialPeelLoop && major_progress() && (_loop_opts_cnt > 0)) {
2217 TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2218 PhaseIdealLoop::optimize(igvn, LoopOptsSkipSplitIf);
2219 _loop_opts_cnt--;
2220 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP2, 2);
2221 if (failing()) return;
2222 }
2223 // Loop opts pass for loop-unrolling before CCP
2224 if(major_progress() && (_loop_opts_cnt > 0)) {
2225 TracePhase tp("idealLoop", &timers[_t_idealLoop]);
2226 PhaseIdealLoop::optimize(igvn, LoopOptsSkipSplitIf);
2227 _loop_opts_cnt--;
2228 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP3, 2);
2229 }
2230 if (!failing()) {
2231 // Verify that last round of loop opts produced a valid graph
2232 PhaseIdealLoop::verify(igvn);
2233 }
2234 }
2235 if (failing()) return;
2236
2237 // Conditional Constant Propagation;
2238 PhaseCCP ccp( &igvn );
2239 assert( true, "Break here to ccp.dump_nodes_and_types(_root,999,1)")do { if (!(true)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2239, "assert(" "true" ") failed", "Break here to ccp.dump_nodes_and_types(_root,999,1)"
); ::breakpoint(); } } while (0)
;
2240 {
2241 TracePhase tp("ccp", &timers[_t_ccp]);
2242 ccp.do_transform();
2243 }
2244 print_method(PHASE_CCP1, 2);
2245
2246 assert( true, "Break here to ccp.dump_old2new_map()")do { if (!(true)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2246, "assert(" "true" ") failed", "Break here to ccp.dump_old2new_map()"
); ::breakpoint(); } } while (0)
;
2247
2248 // Iterative Global Value Numbering, including ideal transforms
2249 {
2250 TracePhase tp("iterGVN2", &timers[_t_iterGVN2]);
2251 igvn = ccp;
2252 igvn.optimize();
2253 }
2254 print_method(PHASE_ITER_GVN2, 2);
2255
2256 if (failing()) return;
2257
2258 // Loop transforms on the ideal graph. Range Check Elimination,
2259 // peeling, unrolling, etc.
2260 if (!optimize_loops(igvn, LoopOptsDefault)) {
2261 return;
2262 }
2263
2264 if (failing()) return;
2265
2266 C->clear_major_progress(); // ensure that major progress is now clear
2267
2268 process_for_post_loop_opts_igvn(igvn);
2269
2270#ifdef ASSERT1
2271 bs->verify_gc_barriers(this, BarrierSetC2::BeforeMacroExpand);
2272#endif
2273
2274 {
2275 TracePhase tp("macroExpand", &timers[_t_macroExpand]);
2276 PhaseMacroExpand mex(igvn);
2277 if (mex.expand_macro_nodes()) {
2278 assert(failing(), "must bail out w/ explicit message")do { if (!(failing())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2278, "assert(" "failing()" ") failed", "must bail out w/ explicit message"
); ::breakpoint(); } } while (0)
;
2279 return;
2280 }
2281 print_method(PHASE_MACRO_EXPANSION, 2);
2282 }
2283
2284 {
2285 TracePhase tp("barrierExpand", &timers[_t_barrierExpand]);
2286 if (bs->expand_barriers(this, igvn)) {
2287 assert(failing(), "must bail out w/ explicit message")do { if (!(failing())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2287, "assert(" "failing()" ") failed", "must bail out w/ explicit message"
); ::breakpoint(); } } while (0)
;
2288 return;
2289 }
2290 print_method(PHASE_BARRIER_EXPANSION, 2);
2291 }
2292
2293 if (C->max_vector_size() > 0) {
2294 C->optimize_logic_cones(igvn);
2295 igvn.optimize();
2296 }
2297
2298 DEBUG_ONLY( _modified_nodes = NULL; )_modified_nodes = __null;
2299
2300 assert(igvn._worklist.size() == 0, "not empty")do { if (!(igvn._worklist.size() == 0)) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2300, "assert(" "igvn._worklist.size() == 0" ") failed", "not empty"
); ::breakpoint(); } } while (0)
;
2301
2302 assert(_late_inlines.length() == 0 || IncrementalInlineMH || IncrementalInlineVirtual, "not empty")do { if (!(_late_inlines.length() == 0 || IncrementalInlineMH
|| IncrementalInlineVirtual)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2302, "assert(" "_late_inlines.length() == 0 || IncrementalInlineMH || IncrementalInlineVirtual"
") failed", "not empty"); ::breakpoint(); } } while (0)
;
2303
2304 if (_late_inlines.length() > 0) {
2305 // More opportunities to optimize virtual and MH calls.
2306 // Though it's maybe too late to perform inlining, strength-reducing them to direct calls is still an option.
2307 process_late_inline_calls_no_inline(igvn);
2308 }
2309 } // (End scope of igvn; run destructor if necessary for asserts.)
2310
2311 check_no_dead_use();
2312
2313 process_print_inlining();
2314
2315 // A method with only infinite loops has no edges entering loops from root
2316 {
2317 TracePhase tp("graphReshape", &timers[_t_graphReshaping]);
2318 if (final_graph_reshaping()) {
2319 assert(failing(), "must bail out w/ explicit message")do { if (!(failing())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2319, "assert(" "failing()" ") failed", "must bail out w/ explicit message"
); ::breakpoint(); } } while (0)
;
2320 return;
2321 }
2322 }
2323
2324 print_method(PHASE_OPTIMIZE_FINISHED, 2);
2325 DEBUG_ONLY(set_phase_optimize_finished();)set_phase_optimize_finished();
2326}
2327
2328#ifdef ASSERT1
2329void Compile::check_no_dead_use() const {
2330 ResourceMark rm;
2331 Unique_Node_List wq;
2332 wq.push(root());
2333 for (uint i = 0; i < wq.size(); ++i) {
2334 Node* n = wq.at(i);
2335 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
2336 Node* u = n->fast_out(j);
2337 if (u->outcnt() == 0 && !u->is_Con()) {
2338 u->dump();
2339 fatal("no reachable node should have no use")do { (*g_assert_poison) = 'X';; report_fatal(INTERNAL_ERROR, "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2339, "no reachable node should have no use"); ::breakpoint
(); } while (0)
;
2340 }
2341 wq.push(u);
2342 }
2343 }
2344}
2345#endif
2346
2347void Compile::inline_vector_reboxing_calls() {
2348 if (C->_vector_reboxing_late_inlines.length() > 0) {
2349 _late_inlines_pos = C->_late_inlines.length();
2350 while (_vector_reboxing_late_inlines.length() > 0) {
2351 CallGenerator* cg = _vector_reboxing_late_inlines.pop();
2352 cg->do_late_inline();
2353 if (failing()) return;
2354 print_method(PHASE_INLINE_VECTOR_REBOX, cg->call_node());
2355 }
2356 _vector_reboxing_late_inlines.trunc_to(0);
2357 }
2358}
2359
2360bool Compile::has_vbox_nodes() {
2361 if (C->_vector_reboxing_late_inlines.length() > 0) {
2362 return true;
2363 }
2364 for (int macro_idx = C->macro_count() - 1; macro_idx >= 0; macro_idx--) {
2365 Node * n = C->macro_node(macro_idx);
2366 assert(n->is_macro(), "only macro nodes expected here")do { if (!(n->is_macro())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2366, "assert(" "n->is_macro()" ") failed", "only macro nodes expected here"
); ::breakpoint(); } } while (0)
;
2367 if (n->Opcode() == Op_VectorUnbox || n->Opcode() == Op_VectorBox || n->Opcode() == Op_VectorBoxAllocate) {
2368 return true;
2369 }
2370 }
2371 return false;
2372}
2373
2374//---------------------------- Bitwise operation packing optimization ---------------------------
2375
2376static bool is_vector_unary_bitwise_op(Node* n) {
2377 return n->Opcode() == Op_XorV &&
2378 n->req() == 2 &&
2379 VectorNode::is_vector_bitwise_not_pattern(n);
2380}
2381
2382static bool is_vector_binary_bitwise_op(Node* n) {
2383 switch (n->Opcode()) {
2384 case Op_AndV:
2385 case Op_OrV:
2386 return n->req() == 2;
2387
2388 case Op_XorV:
2389 return !is_vector_unary_bitwise_op(n);
2390
2391 default:
2392 return false;
2393 }
2394}
2395
2396static bool is_vector_ternary_bitwise_op(Node* n) {
2397 return n->Opcode() == Op_MacroLogicV;
2398}
2399
2400static bool is_vector_bitwise_op(Node* n) {
2401 return is_vector_unary_bitwise_op(n) ||
2402 is_vector_binary_bitwise_op(n) ||
2403 is_vector_ternary_bitwise_op(n);
2404}
2405
2406static bool is_vector_bitwise_cone_root(Node* n) {
2407 if (n->bottom_type()->isa_vectmask() || !is_vector_bitwise_op(n)) {
2408 return false;
2409 }
2410 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
2411 if (is_vector_bitwise_op(n->fast_out(i))) {
2412 return false;
2413 }
2414 }
2415 return true;
2416}
2417
2418static uint collect_unique_inputs(Node* n, Unique_Node_List& partition, Unique_Node_List& inputs) {
2419 uint cnt = 0;
2420 if (is_vector_bitwise_op(n)) {
2421 if (VectorNode::is_vector_bitwise_not_pattern(n)) {
2422 for (uint i = 1; i < n->req(); i++) {
2423 Node* in = n->in(i);
2424 bool skip = VectorNode::is_all_ones_vector(in);
2425 if (!skip && !inputs.member(in)) {
2426 inputs.push(in);
2427 cnt++;
2428 }
2429 }
2430 assert(cnt <= 1, "not unary")do { if (!(cnt <= 1)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2430, "assert(" "cnt <= 1" ") failed", "not unary"); ::breakpoint
(); } } while (0)
;
2431 } else {
2432 uint last_req = n->req();
2433 if (is_vector_ternary_bitwise_op(n)) {
2434 last_req = n->req() - 1; // skip last input
2435 }
2436 for (uint i = 1; i < last_req; i++) {
2437 Node* def = n->in(i);
2438 if (!inputs.member(def)) {
2439 inputs.push(def);
2440 cnt++;
2441 }
2442 }
2443 }
2444 partition.push(n);
2445 } else { // not a bitwise operations
2446 if (!inputs.member(n)) {
2447 inputs.push(n);
2448 cnt++;
2449 }
2450 }
2451 return cnt;
2452}
2453
2454void Compile::collect_logic_cone_roots(Unique_Node_List& list) {
2455 Unique_Node_List useful_nodes;
2456 C->identify_useful_nodes(useful_nodes);
2457
2458 for (uint i = 0; i < useful_nodes.size(); i++) {
2459 Node* n = useful_nodes.at(i);
2460 if (is_vector_bitwise_cone_root(n)) {
2461 list.push(n);
2462 }
2463 }
2464}
2465
2466Node* Compile::xform_to_MacroLogicV(PhaseIterGVN& igvn,
2467 const TypeVect* vt,
2468 Unique_Node_List& partition,
2469 Unique_Node_List& inputs) {
2470 assert(partition.size() == 2 || partition.size() == 3, "not supported")do { if (!(partition.size() == 2 || partition.size() == 3)) {
(*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2470, "assert(" "partition.size() == 2 || partition.size() == 3"
") failed", "not supported"); ::breakpoint(); } } while (0)
;
2471 assert(inputs.size() == 2 || inputs.size() == 3, "not supported")do { if (!(inputs.size() == 2 || inputs.size() == 3)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2471, "assert(" "inputs.size() == 2 || inputs.size() == 3" ") failed"
, "not supported"); ::breakpoint(); } } while (0)
;
2472 assert(Matcher::match_rule_supported_vector(Op_MacroLogicV, vt->length(), vt->element_basic_type()), "not supported")do { if (!(Matcher::match_rule_supported_vector(Op_MacroLogicV
, vt->length(), vt->element_basic_type()))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2472, "assert(" "Matcher::match_rule_supported_vector(Op_MacroLogicV, vt->length(), vt->element_basic_type())"
") failed", "not supported"); ::breakpoint(); } } while (0)
;
2473
2474 Node* in1 = inputs.at(0);
2475 Node* in2 = inputs.at(1);
2476 Node* in3 = (inputs.size() == 3 ? inputs.at(2) : in2);
2477
2478 uint func = compute_truth_table(partition, inputs);
2479 return igvn.transform(MacroLogicVNode::make(igvn, in3, in2, in1, func, vt));
2480}
2481
2482static uint extract_bit(uint func, uint pos) {
2483 return (func & (1 << pos)) >> pos;
2484}
2485
2486//
2487// A macro logic node represents a truth table. It has 4 inputs,
2488// First three inputs corresponds to 3 columns of a truth table
2489// and fourth input captures the logic function.
2490//
2491// eg. fn = (in1 AND in2) OR in3;
2492//
2493// MacroNode(in1,in2,in3,fn)
2494//
2495// -----------------
2496// in1 in2 in3 fn
2497// -----------------
2498// 0 0 0 0
2499// 0 0 1 1
2500// 0 1 0 0
2501// 0 1 1 1
2502// 1 0 0 0
2503// 1 0 1 1
2504// 1 1 0 1
2505// 1 1 1 1
2506//
2507
2508uint Compile::eval_macro_logic_op(uint func, uint in1 , uint in2, uint in3) {
2509 int res = 0;
2510 for (int i = 0; i < 8; i++) {
2511 int bit1 = extract_bit(in1, i);
2512 int bit2 = extract_bit(in2, i);
2513 int bit3 = extract_bit(in3, i);
2514
2515 int func_bit_pos = (bit1 << 2 | bit2 << 1 | bit3);
2516 int func_bit = extract_bit(func, func_bit_pos);
2517
2518 res |= func_bit << i;
2519 }
2520 return res;
2521}
2522
2523static uint eval_operand(Node* n, ResourceHashtable<Node*,uint>& eval_map) {
2524 assert(n != NULL, "")do { if (!(n != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2524, "assert(" "n != __null" ") failed", ""); ::breakpoint
(); } } while (0)
;
2525 assert(eval_map.contains(n), "absent")do { if (!(eval_map.contains(n))) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2525, "assert(" "eval_map.contains(n)" ") failed", "absent"
); ::breakpoint(); } } while (0)
;
2526 return *(eval_map.get(n));
2527}
2528
2529static void eval_operands(Node* n,
2530 uint& func1, uint& func2, uint& func3,
2531 ResourceHashtable<Node*,uint>& eval_map) {
2532 assert(is_vector_bitwise_op(n), "")do { if (!(is_vector_bitwise_op(n))) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2532, "assert(" "is_vector_bitwise_op(n)" ") failed", ""); ::
breakpoint(); } } while (0)
;
2533
2534 if (is_vector_unary_bitwise_op(n)) {
2535 Node* opnd = n->in(1);
2536 if (VectorNode::is_vector_bitwise_not_pattern(n) && VectorNode::is_all_ones_vector(opnd)) {
2537 opnd = n->in(2);
2538 }
2539 func1 = eval_operand(opnd, eval_map);
2540 } else if (is_vector_binary_bitwise_op(n)) {
2541 func1 = eval_operand(n->in(1), eval_map);
2542 func2 = eval_operand(n->in(2), eval_map);
2543 } else {
2544 assert(is_vector_ternary_bitwise_op(n), "unknown operation")do { if (!(is_vector_ternary_bitwise_op(n))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2544, "assert(" "is_vector_ternary_bitwise_op(n)" ") failed"
, "unknown operation"); ::breakpoint(); } } while (0)
;
2545 func1 = eval_operand(n->in(1), eval_map);
2546 func2 = eval_operand(n->in(2), eval_map);
2547 func3 = eval_operand(n->in(3), eval_map);
2548 }
2549}
2550
2551uint Compile::compute_truth_table(Unique_Node_List& partition, Unique_Node_List& inputs) {
2552 assert(inputs.size() <= 3, "sanity")do { if (!(inputs.size() <= 3)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2552, "assert(" "inputs.size() <= 3" ") failed", "sanity"
); ::breakpoint(); } } while (0)
;
2553 ResourceMark rm;
2554 uint res = 0;
2555 ResourceHashtable<Node*,uint> eval_map;
2556
2557 // Populate precomputed functions for inputs.
2558 // Each input corresponds to one column of 3 input truth-table.
2559 uint input_funcs[] = { 0xAA, // (_, _, a) -> a
2560 0xCC, // (_, b, _) -> b
2561 0xF0 }; // (c, _, _) -> c
2562 for (uint i = 0; i < inputs.size(); i++) {
2563 eval_map.put(inputs.at(i), input_funcs[i]);
2564 }
2565
2566 for (uint i = 0; i < partition.size(); i++) {
2567 Node* n = partition.at(i);
2568
2569 uint func1 = 0, func2 = 0, func3 = 0;
2570 eval_operands(n, func1, func2, func3, eval_map);
2571
2572 switch (n->Opcode()) {
2573 case Op_OrV:
2574 assert(func3 == 0, "not binary")do { if (!(func3 == 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2574, "assert(" "func3 == 0" ") failed", "not binary"); ::breakpoint
(); } } while (0)
;
2575 res = func1 | func2;
2576 break;
2577 case Op_AndV:
2578 assert(func3 == 0, "not binary")do { if (!(func3 == 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2578, "assert(" "func3 == 0" ") failed", "not binary"); ::breakpoint
(); } } while (0)
;
2579 res = func1 & func2;
2580 break;
2581 case Op_XorV:
2582 if (VectorNode::is_vector_bitwise_not_pattern(n)) {
2583 assert(func2 == 0 && func3 == 0, "not unary")do { if (!(func2 == 0 && func3 == 0)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2583, "assert(" "func2 == 0 && func3 == 0" ") failed"
, "not unary"); ::breakpoint(); } } while (0)
;
2584 res = (~func1) & 0xFF;
2585 } else {
2586 assert(func3 == 0, "not binary")do { if (!(func3 == 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2586, "assert(" "func3 == 0" ") failed", "not binary"); ::breakpoint
(); } } while (0)
;
2587 res = func1 ^ func2;
2588 }
2589 break;
2590 case Op_MacroLogicV:
2591 // Ordering of inputs may change during evaluation of sub-tree
2592 // containing MacroLogic node as a child node, thus a re-evaluation
2593 // makes sure that function is evaluated in context of current
2594 // inputs.
2595 res = eval_macro_logic_op(n->in(4)->get_int(), func1, func2, func3);
2596 break;
2597
2598 default: assert(false, "not supported: %s", n->Name())do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2598, "assert(" "false" ") failed", "not supported: %s", n->
Name()); ::breakpoint(); } } while (0)
;
2599 }
2600 assert(res <= 0xFF, "invalid")do { if (!(res <= 0xFF)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2600, "assert(" "res <= 0xFF" ") failed", "invalid"); ::
breakpoint(); } } while (0)
;
2601 eval_map.put(n, res);
2602 }
2603 return res;
2604}
2605
2606bool Compile::compute_logic_cone(Node* n, Unique_Node_List& partition, Unique_Node_List& inputs) {
2607 assert(partition.size() == 0, "not empty")do { if (!(partition.size() == 0)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2607, "assert(" "partition.size() == 0" ") failed", "not empty"
); ::breakpoint(); } } while (0)
;
2608 assert(inputs.size() == 0, "not empty")do { if (!(inputs.size() == 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2608, "assert(" "inputs.size() == 0" ") failed", "not empty"
); ::breakpoint(); } } while (0)
;
2609 if (is_vector_ternary_bitwise_op(n)) {
2610 return false;
2611 }
2612
2613 bool is_unary_op = is_vector_unary_bitwise_op(n);
2614 if (is_unary_op) {
2615 assert(collect_unique_inputs(n, partition, inputs) == 1, "not unary")do { if (!(collect_unique_inputs(n, partition, inputs) == 1))
{ (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2615, "assert(" "collect_unique_inputs(n, partition, inputs) == 1"
") failed", "not unary"); ::breakpoint(); } } while (0)
;
2616 return false; // too few inputs
2617 }
2618
2619 assert(is_vector_binary_bitwise_op(n), "not binary")do { if (!(is_vector_binary_bitwise_op(n))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2619, "assert(" "is_vector_binary_bitwise_op(n)" ") failed"
, "not binary"); ::breakpoint(); } } while (0)
;
2620 Node* in1 = n->in(1);
2621 Node* in2 = n->in(2);
2622
2623 int in1_unique_inputs_cnt = collect_unique_inputs(in1, partition, inputs);
2624 int in2_unique_inputs_cnt = collect_unique_inputs(in2, partition, inputs);
2625 partition.push(n);
2626
2627 // Too many inputs?
2628 if (inputs.size() > 3) {
2629 partition.clear();
2630 inputs.clear();
2631 { // Recompute in2 inputs
2632 Unique_Node_List not_used;
2633 in2_unique_inputs_cnt = collect_unique_inputs(in2, not_used, not_used);
2634 }
2635 // Pick the node with minimum number of inputs.
2636 if (in1_unique_inputs_cnt >= 3 && in2_unique_inputs_cnt >= 3) {
2637 return false; // still too many inputs
2638 }
2639 // Recompute partition & inputs.
2640 Node* child = (in1_unique_inputs_cnt < in2_unique_inputs_cnt ? in1 : in2);
2641 collect_unique_inputs(child, partition, inputs);
2642
2643 Node* other_input = (in1_unique_inputs_cnt < in2_unique_inputs_cnt ? in2 : in1);
2644 inputs.push(other_input);
2645
2646 partition.push(n);
2647 }
2648
2649 return (partition.size() == 2 || partition.size() == 3) &&
2650 (inputs.size() == 2 || inputs.size() == 3);
2651}
2652
2653
2654void Compile::process_logic_cone_root(PhaseIterGVN &igvn, Node *n, VectorSet &visited) {
2655 assert(is_vector_bitwise_op(n), "not a root")do { if (!(is_vector_bitwise_op(n))) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2655, "assert(" "is_vector_bitwise_op(n)" ") failed", "not a root"
); ::breakpoint(); } } while (0)
;
2656
2657 visited.set(n->_idx);
2658
2659 // 1) Do a DFS walk over the logic cone.
2660 for (uint i = 1; i < n->req(); i++) {
2661 Node* in = n->in(i);
2662 if (!visited.test(in->_idx) && is_vector_bitwise_op(in)) {
2663 process_logic_cone_root(igvn, in, visited);
2664 }
2665 }
2666
2667 // 2) Bottom up traversal: Merge node[s] with
2668 // the parent to form macro logic node.
2669 Unique_Node_List partition;
2670 Unique_Node_List inputs;
2671 if (compute_logic_cone(n, partition, inputs)) {
2672 const TypeVect* vt = n->bottom_type()->is_vect();
2673 Node* macro_logic = xform_to_MacroLogicV(igvn, vt, partition, inputs);
2674 igvn.replace_node(n, macro_logic);
2675 }
2676}
2677
2678void Compile::optimize_logic_cones(PhaseIterGVN &igvn) {
2679 ResourceMark rm;
2680 if (Matcher::match_rule_supported(Op_MacroLogicV)) {
2681 Unique_Node_List list;
2682 collect_logic_cone_roots(list);
2683
2684 while (list.size() > 0) {
2685 Node* n = list.pop();
2686 const TypeVect* vt = n->bottom_type()->is_vect();
2687 bool supported = Matcher::match_rule_supported_vector(Op_MacroLogicV, vt->length(), vt->element_basic_type());
2688 if (supported) {
2689 VectorSet visited(comp_arena());
2690 process_logic_cone_root(igvn, n, visited);
2691 }
2692 }
2693 }
2694}
2695
2696//------------------------------Code_Gen---------------------------------------
2697// Given a graph, generate code for it
2698void Compile::Code_Gen() {
2699 if (failing()) {
2700 return;
2701 }
2702
2703 // Perform instruction selection. You might think we could reclaim Matcher
2704 // memory PDQ, but actually the Matcher is used in generating spill code.
2705 // Internals of the Matcher (including some VectorSets) must remain live
2706 // for awhile - thus I cannot reclaim Matcher memory lest a VectorSet usage
2707 // set a bit in reclaimed memory.
2708
2709 // In debug mode can dump m._nodes.dump() for mapping of ideal to machine
2710 // nodes. Mapping is only valid at the root of each matched subtree.
2711 NOT_PRODUCT( verify_graph_edges(); )verify_graph_edges();
2712
2713 Matcher matcher;
2714 _matcher = &matcher;
2715 {
2716 TracePhase tp("matcher", &timers[_t_matcher]);
2717 matcher.match();
2718 if (failing()) {
2719 return;
2720 }
2721 }
2722 // In debug mode can dump m._nodes.dump() for mapping of ideal to machine
2723 // nodes. Mapping is only valid at the root of each matched subtree.
2724 NOT_PRODUCT( verify_graph_edges(); )verify_graph_edges();
2725
2726 // If you have too many nodes, or if matching has failed, bail out
2727 check_node_count(0, "out of nodes matching instructions");
2728 if (failing()) {
2729 return;
2730 }
2731
2732 print_method(PHASE_MATCHING, 2);
2733
2734 // Build a proper-looking CFG
2735 PhaseCFG cfg(node_arena(), root(), matcher);
2736 _cfg = &cfg;
2737 {
2738 TracePhase tp("scheduler", &timers[_t_scheduler]);
2739 bool success = cfg.do_global_code_motion();
2740 if (!success) {
2741 return;
2742 }
2743
2744 print_method(PHASE_GLOBAL_CODE_MOTION, 2);
2745 NOT_PRODUCT( verify_graph_edges(); )verify_graph_edges();
2746 cfg.verify();
2747 }
2748
2749 PhaseChaitin regalloc(unique(), cfg, matcher, false);
2750 _regalloc = &regalloc;
2751 {
2752 TracePhase tp("regalloc", &timers[_t_registerAllocation]);
2753 // Perform register allocation. After Chaitin, use-def chains are
2754 // no longer accurate (at spill code) and so must be ignored.
2755 // Node->LRG->reg mappings are still accurate.
2756 _regalloc->Register_Allocate();
2757
2758 // Bail out if the allocator builds too many nodes
2759 if (failing()) {
2760 return;
2761 }
2762 }
2763
2764 // Prior to register allocation we kept empty basic blocks in case the
2765 // the allocator needed a place to spill. After register allocation we
2766 // are not adding any new instructions. If any basic block is empty, we
2767 // can now safely remove it.
2768 {
2769 TracePhase tp("blockOrdering", &timers[_t_blockOrdering]);
2770 cfg.remove_empty_blocks();
2771 if (do_freq_based_layout()) {
2772 PhaseBlockLayout layout(cfg);
2773 } else {
2774 cfg.set_loop_alignment();
2775 }
2776 cfg.fixup_flow();
2777 }
2778
2779 // Apply peephole optimizations
2780 if( OptoPeephole ) {
2781 TracePhase tp("peephole", &timers[_t_peephole]);
2782 PhasePeephole peep( _regalloc, cfg);
2783 peep.do_transform();
2784 }
2785
2786 // Do late expand if CPU requires this.
2787 if (Matcher::require_postalloc_expand) {
2788 TracePhase tp("postalloc_expand", &timers[_t_postalloc_expand]);
2789 cfg.postalloc_expand(_regalloc);
2790 }
2791
2792 // Convert Nodes to instruction bits in a buffer
2793 {
2794 TracePhase tp("output", &timers[_t_output]);
2795 PhaseOutput output;
2796 output.Output();
2797 if (failing()) return;
2798 output.install();
2799 }
2800
2801 print_method(PHASE_FINAL_CODE);
2802
2803 // He's dead, Jim.
2804 _cfg = (PhaseCFG*)((intptr_t)0xdeadbeef);
2805 _regalloc = (PhaseChaitin*)((intptr_t)0xdeadbeef);
2806}
2807
2808//------------------------------Final_Reshape_Counts---------------------------
2809// This class defines counters to help identify when a method
2810// may/must be executed using hardware with only 24-bit precision.
2811struct Final_Reshape_Counts : public StackObj {
2812 int _call_count; // count non-inlined 'common' calls
2813 int _float_count; // count float ops requiring 24-bit precision
2814 int _double_count; // count double ops requiring more precision
2815 int _java_call_count; // count non-inlined 'java' calls
2816 int _inner_loop_count; // count loops which need alignment
2817 VectorSet _visited; // Visitation flags
2818 Node_List _tests; // Set of IfNodes & PCTableNodes
2819
2820 Final_Reshape_Counts() :
2821 _call_count(0), _float_count(0), _double_count(0),
2822 _java_call_count(0), _inner_loop_count(0) { }
2823
2824 void inc_call_count () { _call_count ++; }
2825 void inc_float_count () { _float_count ++; }
2826 void inc_double_count() { _double_count++; }
2827 void inc_java_call_count() { _java_call_count++; }
2828 void inc_inner_loop_count() { _inner_loop_count++; }
2829
2830 int get_call_count () const { return _call_count ; }
2831 int get_float_count () const { return _float_count ; }
2832 int get_double_count() const { return _double_count; }
2833 int get_java_call_count() const { return _java_call_count; }
2834 int get_inner_loop_count() const { return _inner_loop_count; }
2835};
2836
2837// Eliminate trivially redundant StoreCMs and accumulate their
2838// precedence edges.
2839void Compile::eliminate_redundant_card_marks(Node* n) {
2840 assert(n->Opcode() == Op_StoreCM, "expected StoreCM")do { if (!(n->Opcode() == Op_StoreCM)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2840, "assert(" "n->Opcode() == Op_StoreCM" ") failed", "expected StoreCM"
); ::breakpoint(); } } while (0)
;
2841 if (n->in(MemNode::Address)->outcnt() > 1) {
2842 // There are multiple users of the same address so it might be
2843 // possible to eliminate some of the StoreCMs
2844 Node* mem = n->in(MemNode::Memory);
2845 Node* adr = n->in(MemNode::Address);
2846 Node* val = n->in(MemNode::ValueIn);
2847 Node* prev = n;
2848 bool done = false;
2849 // Walk the chain of StoreCMs eliminating ones that match. As
2850 // long as it's a chain of single users then the optimization is
2851 // safe. Eliminating partially redundant StoreCMs would require
2852 // cloning copies down the other paths.
2853 while (mem->Opcode() == Op_StoreCM && mem->outcnt() == 1 && !done) {
2854 if (adr == mem->in(MemNode::Address) &&
2855 val == mem->in(MemNode::ValueIn)) {
2856 // redundant StoreCM
2857 if (mem->req() > MemNode::OopStore) {
2858 // Hasn't been processed by this code yet.
2859 n->add_prec(mem->in(MemNode::OopStore));
2860 } else {
2861 // Already converted to precedence edge
2862 for (uint i = mem->req(); i < mem->len(); i++) {
2863 // Accumulate any precedence edges
2864 if (mem->in(i) != NULL__null) {
2865 n->add_prec(mem->in(i));
2866 }
2867 }
2868 // Everything above this point has been processed.
2869 done = true;
2870 }
2871 // Eliminate the previous StoreCM
2872 prev->set_req(MemNode::Memory, mem->in(MemNode::Memory));
2873 assert(mem->outcnt() == 0, "should be dead")do { if (!(mem->outcnt() == 0)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2873, "assert(" "mem->outcnt() == 0" ") failed", "should be dead"
); ::breakpoint(); } } while (0)
;
2874 mem->disconnect_inputs(this);
2875 } else {
2876 prev = mem;
2877 }
2878 mem = prev->in(MemNode::Memory);
2879 }
2880 }
2881}
2882
2883//------------------------------final_graph_reshaping_impl----------------------
2884// Implement items 1-5 from final_graph_reshaping below.
2885void Compile::final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc) {
2886
2887 if ( n->outcnt() == 0 ) return; // dead node
2888 uint nop = n->Opcode();
2889
2890 // Check for 2-input instruction with "last use" on right input.
2891 // Swap to left input. Implements item (2).
2892 if( n->req() == 3 && // two-input instruction
2893 n->in(1)->outcnt() > 1 && // left use is NOT a last use
2894 (!n->in(1)->is_Phi() || n->in(1)->in(2) != n) && // it is not data loop
2895 n->in(2)->outcnt() == 1 &&// right use IS a last use
2896 !n->in(2)->is_Con() ) { // right use is not a constant
2897 // Check for commutative opcode
2898 switch( nop ) {
2899 case Op_AddI: case Op_AddF: case Op_AddD: case Op_AddL:
2900 case Op_MaxI: case Op_MaxL: case Op_MaxF: case Op_MaxD:
2901 case Op_MinI: case Op_MinL: case Op_MinF: case Op_MinD:
2902 case Op_MulI: case Op_MulF: case Op_MulD: case Op_MulL:
2903 case Op_AndL: case Op_XorL: case Op_OrL:
2904 case Op_AndI: case Op_XorI: case Op_OrI: {
2905 // Move "last use" input to left by swapping inputs
2906 n->swap_edges(1, 2);
2907 break;
2908 }
2909 default:
2910 break;
2911 }
2912 }
2913
2914#ifdef ASSERT1
2915 if( n->is_Mem() ) {
2916 int alias_idx = get_alias_index(n->as_Mem()->adr_type());
2917 assert( n->in(0) != NULL || alias_idx != Compile::AliasIdxRaw ||do { if (!(n->in(0) != __null || alias_idx != Compile::AliasIdxRaw
|| n->is_Load() && (n->as_Load()->bottom_type
()->isa_oopptr() || LoadNode::is_immutable_value(n->in(
MemNode::Address))))) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2921, "assert(" "n->in(0) != __null || alias_idx != Compile::AliasIdxRaw || n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() || LoadNode::is_immutable_value(n->in(MemNode::Address)))"
") failed", "raw memory operations should have control edge"
); ::breakpoint(); } } while (0)
2918 // oop will be recorded in oop map if load crosses safepointdo { if (!(n->in(0) != __null || alias_idx != Compile::AliasIdxRaw
|| n->is_Load() && (n->as_Load()->bottom_type
()->isa_oopptr() || LoadNode::is_immutable_value(n->in(
MemNode::Address))))) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2921, "assert(" "n->in(0) != __null || alias_idx != Compile::AliasIdxRaw || n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() || LoadNode::is_immutable_value(n->in(MemNode::Address)))"
") failed", "raw memory operations should have control edge"
); ::breakpoint(); } } while (0)
2919 n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() ||do { if (!(n->in(0) != __null || alias_idx != Compile::AliasIdxRaw
|| n->is_Load() && (n->as_Load()->bottom_type
()->isa_oopptr() || LoadNode::is_immutable_value(n->in(
MemNode::Address))))) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2921, "assert(" "n->in(0) != __null || alias_idx != Compile::AliasIdxRaw || n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() || LoadNode::is_immutable_value(n->in(MemNode::Address)))"
") failed", "raw memory operations should have control edge"
); ::breakpoint(); } } while (0)
2920 LoadNode::is_immutable_value(n->in(MemNode::Address))),do { if (!(n->in(0) != __null || alias_idx != Compile::AliasIdxRaw
|| n->is_Load() && (n->as_Load()->bottom_type
()->isa_oopptr() || LoadNode::is_immutable_value(n->in(
MemNode::Address))))) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2921, "assert(" "n->in(0) != __null || alias_idx != Compile::AliasIdxRaw || n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() || LoadNode::is_immutable_value(n->in(MemNode::Address)))"
") failed", "raw memory operations should have control edge"
); ::breakpoint(); } } while (0)
2921 "raw memory operations should have control edge")do { if (!(n->in(0) != __null || alias_idx != Compile::AliasIdxRaw
|| n->is_Load() && (n->as_Load()->bottom_type
()->isa_oopptr() || LoadNode::is_immutable_value(n->in(
MemNode::Address))))) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2921, "assert(" "n->in(0) != __null || alias_idx != Compile::AliasIdxRaw || n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() || LoadNode::is_immutable_value(n->in(MemNode::Address)))"
") failed", "raw memory operations should have control edge"
); ::breakpoint(); } } while (0)
;
2922 }
2923 if (n->is_MemBar()) {
2924 MemBarNode* mb = n->as_MemBar();
2925 if (mb->trailing_store() || mb->trailing_load_store()) {
2926 assert(mb->leading_membar()->trailing_membar() == mb, "bad membar pair")do { if (!(mb->leading_membar()->trailing_membar() == mb
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2926, "assert(" "mb->leading_membar()->trailing_membar() == mb"
") failed", "bad membar pair"); ::breakpoint(); } } while (0
)
;
2927 Node* mem = BarrierSet::barrier_set()->barrier_set_c2()->step_over_gc_barrier(mb->in(MemBarNode::Precedent));
2928 assert((mb->trailing_store() && mem->is_Store() && mem->as_Store()->is_release()) ||do { if (!((mb->trailing_store() && mem->is_Store
() && mem->as_Store()->is_release()) || (mb->
trailing_load_store() && mem->is_LoadStore()))) { (
*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2929, "assert(" "(mb->trailing_store() && mem->is_Store() && mem->as_Store()->is_release()) || (mb->trailing_load_store() && mem->is_LoadStore())"
") failed", "missing mem op"); ::breakpoint(); } } while (0)
2929 (mb->trailing_load_store() && mem->is_LoadStore()), "missing mem op")do { if (!((mb->trailing_store() && mem->is_Store
() && mem->as_Store()->is_release()) || (mb->
trailing_load_store() && mem->is_LoadStore()))) { (
*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2929, "assert(" "(mb->trailing_store() && mem->is_Store() && mem->as_Store()->is_release()) || (mb->trailing_load_store() && mem->is_LoadStore())"
") failed", "missing mem op"); ::breakpoint(); } } while (0)
;
2930 } else if (mb->leading()) {
2931 assert(mb->trailing_membar()->leading_membar() == mb, "bad membar pair")do { if (!(mb->trailing_membar()->leading_membar() == mb
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 2931, "assert(" "mb->trailing_membar()->leading_membar() == mb"
") failed", "bad membar pair"); ::breakpoint(); } } while (0
)
;
2932 }
2933 }
2934#endif
2935 // Count FPU ops and common calls, implements item (3)
2936 bool gc_handled = BarrierSet::barrier_set()->barrier_set_c2()->final_graph_reshaping(this, n, nop);
2937 if (!gc_handled) {
2938 final_graph_reshaping_main_switch(n, frc, nop);
2939 }
2940
2941 // Collect CFG split points
2942 if (n->is_MultiBranch() && !n->is_RangeCheck()) {
2943 frc._tests.push(n);
2944 }
2945}
2946
2947void Compile::final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop) {
2948 switch( nop ) {
2949 // Count all float operations that may use FPU
2950 case Op_AddF:
2951 case Op_SubF:
2952 case Op_MulF:
2953 case Op_DivF:
2954 case Op_NegF:
2955 case Op_ModF:
2956 case Op_ConvI2F:
2957 case Op_ConF:
2958 case Op_CmpF:
2959 case Op_CmpF3:
2960 case Op_StoreF:
2961 case Op_LoadF:
2962 // case Op_ConvL2F: // longs are split into 32-bit halves
2963 frc.inc_float_count();
2964 break;
2965
2966 case Op_ConvF2D:
2967 case Op_ConvD2F:
2968 frc.inc_float_count();
2969 frc.inc_double_count();
2970 break;
2971
2972 // Count all double operations that may use FPU
2973 case Op_AddD:
2974 case Op_SubD:
2975 case Op_MulD:
2976 case Op_DivD:
2977 case Op_NegD:
2978 case Op_ModD:
2979 case Op_ConvI2D:
2980 case Op_ConvD2I:
2981 // case Op_ConvL2D: // handled by leaf call
2982 // case Op_ConvD2L: // handled by leaf call
2983 case Op_ConD:
2984 case Op_CmpD:
2985 case Op_CmpD3:
2986 case Op_StoreD:
2987 case Op_LoadD:
2988 case Op_LoadD_unaligned:
2989 frc.inc_double_count();
2990 break;
2991 case Op_Opaque1: // Remove Opaque Nodes before matching
2992 case Op_Opaque2: // Remove Opaque Nodes before matching
2993 case Op_Opaque3:
2994 n->subsume_by(n->in(1), this);
2995 break;
2996 case Op_CallStaticJava:
2997 case Op_CallJava:
2998 case Op_CallDynamicJava:
2999 frc.inc_java_call_count(); // Count java call site;
3000 case Op_CallRuntime:
3001 case Op_CallLeaf:
3002 case Op_CallLeafVector:
3003 case Op_CallNative:
3004 case Op_CallLeafNoFP: {
3005 assert (n->is_Call(), "")do { if (!(n->is_Call())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3005, "assert(" "n->is_Call()" ") failed", ""); ::breakpoint
(); } } while (0)
;
3006 CallNode *call = n->as_Call();
3007 // Count call sites where the FP mode bit would have to be flipped.
3008 // Do not count uncommon runtime calls:
3009 // uncommon_trap, _complete_monitor_locking, _complete_monitor_unlocking,
3010 // _new_Java, _new_typeArray, _new_objArray, _rethrow_Java, ...
3011 if (!call->is_CallStaticJava() || !call->as_CallStaticJava()->_name) {
3012 frc.inc_call_count(); // Count the call site
3013 } else { // See if uncommon argument is shared
3014 Node *n = call->in(TypeFunc::Parms);
3015 int nop = n->Opcode();
3016 // Clone shared simple arguments to uncommon calls, item (1).
3017 if (n->outcnt() > 1 &&
3018 !n->is_Proj() &&
3019 nop != Op_CreateEx &&
3020 nop != Op_CheckCastPP &&
3021 nop != Op_DecodeN &&
3022 nop != Op_DecodeNKlass &&
3023 !n->is_Mem() &&
3024 !n->is_Phi()) {
3025 Node *x = n->clone();
3026 call->set_req(TypeFunc::Parms, x);
3027 }
3028 }
3029 break;
3030 }
3031
3032 case Op_StoreCM:
3033 {
3034 // Convert OopStore dependence into precedence edge
3035 Node* prec = n->in(MemNode::OopStore);
3036 n->del_req(MemNode::OopStore);
3037 n->add_prec(prec);
3038 eliminate_redundant_card_marks(n);
3039 }
3040
3041 // fall through
3042
3043 case Op_StoreB:
3044 case Op_StoreC:
3045 case Op_StorePConditional:
3046 case Op_StoreI:
3047 case Op_StoreL:
3048 case Op_StoreIConditional:
3049 case Op_StoreLConditional:
3050 case Op_CompareAndSwapB:
3051 case Op_CompareAndSwapS:
3052 case Op_CompareAndSwapI:
3053 case Op_CompareAndSwapL:
3054 case Op_CompareAndSwapP:
3055 case Op_CompareAndSwapN:
3056 case Op_WeakCompareAndSwapB:
3057 case Op_WeakCompareAndSwapS:
3058 case Op_WeakCompareAndSwapI:
3059 case Op_WeakCompareAndSwapL:
3060 case Op_WeakCompareAndSwapP:
3061 case Op_WeakCompareAndSwapN:
3062 case Op_CompareAndExchangeB:
3063 case Op_CompareAndExchangeS:
3064 case Op_CompareAndExchangeI:
3065 case Op_CompareAndExchangeL:
3066 case Op_CompareAndExchangeP:
3067 case Op_CompareAndExchangeN:
3068 case Op_GetAndAddS:
3069 case Op_GetAndAddB:
3070 case Op_GetAndAddI:
3071 case Op_GetAndAddL:
3072 case Op_GetAndSetS:
3073 case Op_GetAndSetB:
3074 case Op_GetAndSetI:
3075 case Op_GetAndSetL:
3076 case Op_GetAndSetP:
3077 case Op_GetAndSetN:
3078 case Op_StoreP:
3079 case Op_StoreN:
3080 case Op_StoreNKlass:
3081 case Op_LoadB:
3082 case Op_LoadUB:
3083 case Op_LoadUS:
3084 case Op_LoadI:
3085 case Op_LoadKlass:
3086 case Op_LoadNKlass:
3087 case Op_LoadL:
3088 case Op_LoadL_unaligned:
3089 case Op_LoadPLocked:
3090 case Op_LoadP:
3091 case Op_LoadN:
3092 case Op_LoadRange:
3093 case Op_LoadS:
3094 break;
3095
3096 case Op_AddP: { // Assert sane base pointers
3097 Node *addp = n->in(AddPNode::Address);
3098 assert( !addp->is_AddP() ||do { if (!(!addp->is_AddP() || addp->in(AddPNode::Base)
->is_top() || addp->in(AddPNode::Base) == n->in(AddPNode
::Base))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3101, "assert(" "!addp->is_AddP() || addp->in(AddPNode::Base)->is_top() || addp->in(AddPNode::Base) == n->in(AddPNode::Base)"
") failed", "Base pointers must match (addp %u)", addp->_idx
); ::breakpoint(); } } while (0)
3099 addp->in(AddPNode::Base)->is_top() || // Top OK for allocationdo { if (!(!addp->is_AddP() || addp->in(AddPNode::Base)
->is_top() || addp->in(AddPNode::Base) == n->in(AddPNode
::Base))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3101, "assert(" "!addp->is_AddP() || addp->in(AddPNode::Base)->is_top() || addp->in(AddPNode::Base) == n->in(AddPNode::Base)"
") failed", "Base pointers must match (addp %u)", addp->_idx
); ::breakpoint(); } } while (0)
3100 addp->in(AddPNode::Base) == n->in(AddPNode::Base),do { if (!(!addp->is_AddP() || addp->in(AddPNode::Base)
->is_top() || addp->in(AddPNode::Base) == n->in(AddPNode
::Base))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3101, "assert(" "!addp->is_AddP() || addp->in(AddPNode::Base)->is_top() || addp->in(AddPNode::Base) == n->in(AddPNode::Base)"
") failed", "Base pointers must match (addp %u)", addp->_idx
); ::breakpoint(); } } while (0)
3101 "Base pointers must match (addp %u)", addp->_idx )do { if (!(!addp->is_AddP() || addp->in(AddPNode::Base)
->is_top() || addp->in(AddPNode::Base) == n->in(AddPNode
::Base))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3101, "assert(" "!addp->is_AddP() || addp->in(AddPNode::Base)->is_top() || addp->in(AddPNode::Base) == n->in(AddPNode::Base)"
") failed", "Base pointers must match (addp %u)", addp->_idx
); ::breakpoint(); } } while (0)
;
3102#ifdef _LP641
3103 if ((UseCompressedOops || UseCompressedClassPointers) &&
3104 addp->Opcode() == Op_ConP &&
3105 addp == n->in(AddPNode::Base) &&
3106 n->in(AddPNode::Offset)->is_Con()) {
3107 // If the transformation of ConP to ConN+DecodeN is beneficial depends
3108 // on the platform and on the compressed oops mode.
3109 // Use addressing with narrow klass to load with offset on x86.
3110 // Some platforms can use the constant pool to load ConP.
3111 // Do this transformation here since IGVN will convert ConN back to ConP.
3112 const Type* t = addp->bottom_type();
3113 bool is_oop = t->isa_oopptr() != NULL__null;
3114 bool is_klass = t->isa_klassptr() != NULL__null;
3115
3116 if ((is_oop && Matcher::const_oop_prefer_decode() ) ||
3117 (is_klass && Matcher::const_klass_prefer_decode())) {
3118 Node* nn = NULL__null;
3119
3120 int op = is_oop ? Op_ConN : Op_ConNKlass;
3121
3122 // Look for existing ConN node of the same exact type.
3123 Node* r = root();
3124 uint cnt = r->outcnt();
3125 for (uint i = 0; i < cnt; i++) {
3126 Node* m = r->raw_out(i);
3127 if (m!= NULL__null && m->Opcode() == op &&
3128 m->bottom_type()->make_ptr() == t) {
3129 nn = m;
3130 break;
3131 }
3132 }
3133 if (nn != NULL__null) {
3134 // Decode a narrow oop to match address
3135 // [R12 + narrow_oop_reg<<3 + offset]
3136 if (is_oop) {
3137 nn = new DecodeNNode(nn, t);
3138 } else {
3139 nn = new DecodeNKlassNode(nn, t);
3140 }
3141 // Check for succeeding AddP which uses the same Base.
3142 // Otherwise we will run into the assertion above when visiting that guy.
3143 for (uint i = 0; i < n->outcnt(); ++i) {
3144 Node *out_i = n->raw_out(i);
3145 if (out_i && out_i->is_AddP() && out_i->in(AddPNode::Base) == addp) {
3146 out_i->set_req(AddPNode::Base, nn);
3147#ifdef ASSERT1
3148 for (uint j = 0; j < out_i->outcnt(); ++j) {
3149 Node *out_j = out_i->raw_out(j);
3150 assert(out_j == NULL || !out_j->is_AddP() || out_j->in(AddPNode::Base) != addp,do { if (!(out_j == __null || !out_j->is_AddP() || out_j->
in(AddPNode::Base) != addp)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3151, "assert(" "out_j == __null || !out_j->is_AddP() || out_j->in(AddPNode::Base) != addp"
") failed", "more than 2 AddP nodes in a chain (out_j %u)", out_j
->_idx); ::breakpoint(); } } while (0)
3151 "more than 2 AddP nodes in a chain (out_j %u)", out_j->_idx)do { if (!(out_j == __null || !out_j->is_AddP() || out_j->
in(AddPNode::Base) != addp)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3151, "assert(" "out_j == __null || !out_j->is_AddP() || out_j->in(AddPNode::Base) != addp"
") failed", "more than 2 AddP nodes in a chain (out_j %u)", out_j
->_idx); ::breakpoint(); } } while (0)
;
3152 }
3153#endif
3154 }
3155 }
3156 n->set_req(AddPNode::Base, nn);
3157 n->set_req(AddPNode::Address, nn);
3158 if (addp->outcnt() == 0) {
3159 addp->disconnect_inputs(this);
3160 }
3161 }
3162 }
3163 }
3164#endif
3165 break;
3166 }
3167
3168 case Op_CastPP: {
3169 // Remove CastPP nodes to gain more freedom during scheduling but
3170 // keep the dependency they encode as control or precedence edges
3171 // (if control is set already) on memory operations. Some CastPP
3172 // nodes don't have a control (don't carry a dependency): skip
3173 // those.
3174 if (n->in(0) != NULL__null) {
3175 ResourceMark rm;
3176 Unique_Node_List wq;
3177 wq.push(n);
3178 for (uint next = 0; next < wq.size(); ++next) {
3179 Node *m = wq.at(next);
3180 for (DUIterator_Fast imax, i = m->fast_outs(imax); i < imax; i++) {
3181 Node* use = m->fast_out(i);
3182 if (use->is_Mem() || use->is_EncodeNarrowPtr()) {
3183 use->ensure_control_or_add_prec(n->in(0));
3184 } else {
3185 switch(use->Opcode()) {
3186 case Op_AddP:
3187 case Op_DecodeN:
3188 case Op_DecodeNKlass:
3189 case Op_CheckCastPP:
3190 case Op_CastPP:
3191 wq.push(use);
3192 break;
3193 }
3194 }
3195 }
3196 }
3197 }
3198 const bool is_LP64 = LP64_ONLY(true)true NOT_LP64(false);
3199 if (is_LP64 && n->in(1)->is_DecodeN() && Matcher::gen_narrow_oop_implicit_null_checks()) {
3200 Node* in1 = n->in(1);
3201 const Type* t = n->bottom_type();
3202 Node* new_in1 = in1->clone();
3203 new_in1->as_DecodeN()->set_type(t);
3204
3205 if (!Matcher::narrow_oop_use_complex_address()) {
3206 //
3207 // x86, ARM and friends can handle 2 adds in addressing mode
3208 // and Matcher can fold a DecodeN node into address by using
3209 // a narrow oop directly and do implicit NULL check in address:
3210 //
3211 // [R12 + narrow_oop_reg<<3 + offset]
3212 // NullCheck narrow_oop_reg
3213 //
3214 // On other platforms (Sparc) we have to keep new DecodeN node and
3215 // use it to do implicit NULL check in address:
3216 //
3217 // decode_not_null narrow_oop_reg, base_reg
3218 // [base_reg + offset]
3219 // NullCheck base_reg
3220 //
3221 // Pin the new DecodeN node to non-null path on these platform (Sparc)
3222 // to keep the information to which NULL check the new DecodeN node
3223 // corresponds to use it as value in implicit_null_check().
3224 //
3225 new_in1->set_req(0, n->in(0));
3226 }
3227
3228 n->subsume_by(new_in1, this);
3229 if (in1->outcnt() == 0) {
3230 in1->disconnect_inputs(this);
3231 }
3232 } else {
3233 n->subsume_by(n->in(1), this);
3234 if (n->outcnt() == 0) {
3235 n->disconnect_inputs(this);
3236 }
3237 }
3238 break;
3239 }
3240#ifdef _LP641
3241 case Op_CmpP:
3242 // Do this transformation here to preserve CmpPNode::sub() and
3243 // other TypePtr related Ideal optimizations (for example, ptr nullness).
3244 if (n->in(1)->is_DecodeNarrowPtr() || n->in(2)->is_DecodeNarrowPtr()) {
3245 Node* in1 = n->in(1);
3246 Node* in2 = n->in(2);
3247 if (!in1->is_DecodeNarrowPtr()) {
3248 in2 = in1;
3249 in1 = n->in(2);
3250 }
3251 assert(in1->is_DecodeNarrowPtr(), "sanity")do { if (!(in1->is_DecodeNarrowPtr())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3251, "assert(" "in1->is_DecodeNarrowPtr()" ") failed", "sanity"
); ::breakpoint(); } } while (0)
;
3252
3253 Node* new_in2 = NULL__null;
3254 if (in2->is_DecodeNarrowPtr()) {
3255 assert(in2->Opcode() == in1->Opcode(), "must be same node type")do { if (!(in2->Opcode() == in1->Opcode())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3255, "assert(" "in2->Opcode() == in1->Opcode()" ") failed"
, "must be same node type"); ::breakpoint(); } } while (0)
;
3256 new_in2 = in2->in(1);
3257 } else if (in2->Opcode() == Op_ConP) {
3258 const Type* t = in2->bottom_type();
3259 if (t == TypePtr::NULL_PTR) {
3260 assert(in1->is_DecodeN(), "compare klass to null?")do { if (!(in1->is_DecodeN())) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3260, "assert(" "in1->is_DecodeN()" ") failed", "compare klass to null?"
); ::breakpoint(); } } while (0)
;
3261 // Don't convert CmpP null check into CmpN if compressed
3262 // oops implicit null check is not generated.
3263 // This will allow to generate normal oop implicit null check.
3264 if (Matcher::gen_narrow_oop_implicit_null_checks())
3265 new_in2 = ConNode::make(TypeNarrowOop::NULL_PTR);
3266 //
3267 // This transformation together with CastPP transformation above
3268 // will generated code for implicit NULL checks for compressed oops.
3269 //
3270 // The original code after Optimize()
3271 //
3272 // LoadN memory, narrow_oop_reg
3273 // decode narrow_oop_reg, base_reg
3274 // CmpP base_reg, NULL
3275 // CastPP base_reg // NotNull
3276 // Load [base_reg + offset], val_reg
3277 //
3278 // after these transformations will be
3279 //
3280 // LoadN memory, narrow_oop_reg
3281 // CmpN narrow_oop_reg, NULL
3282 // decode_not_null narrow_oop_reg, base_reg
3283 // Load [base_reg + offset], val_reg
3284 //
3285 // and the uncommon path (== NULL) will use narrow_oop_reg directly
3286 // since narrow oops can be used in debug info now (see the code in
3287 // final_graph_reshaping_walk()).
3288 //
3289 // At the end the code will be matched to
3290 // on x86:
3291 //
3292 // Load_narrow_oop memory, narrow_oop_reg
3293 // Load [R12 + narrow_oop_reg<<3 + offset], val_reg
3294 // NullCheck narrow_oop_reg
3295 //
3296 // and on sparc:
3297 //
3298 // Load_narrow_oop memory, narrow_oop_reg
3299 // decode_not_null narrow_oop_reg, base_reg
3300 // Load [base_reg + offset], val_reg
3301 // NullCheck base_reg
3302 //
3303 } else if (t->isa_oopptr()) {
3304 new_in2 = ConNode::make(t->make_narrowoop());
3305 } else if (t->isa_klassptr()) {
3306 new_in2 = ConNode::make(t->make_narrowklass());
3307 }
3308 }
3309 if (new_in2 != NULL__null) {
3310 Node* cmpN = new CmpNNode(in1->in(1), new_in2);
3311 n->subsume_by(cmpN, this);
3312 if (in1->outcnt() == 0) {
3313 in1->disconnect_inputs(this);
3314 }
3315 if (in2->outcnt() == 0) {
3316 in2->disconnect_inputs(this);
3317 }
3318 }
3319 }
3320 break;
3321
3322 case Op_DecodeN:
3323 case Op_DecodeNKlass:
3324 assert(!n->in(1)->is_EncodeNarrowPtr(), "should be optimized out")do { if (!(!n->in(1)->is_EncodeNarrowPtr())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3324, "assert(" "!n->in(1)->is_EncodeNarrowPtr()" ") failed"
, "should be optimized out"); ::breakpoint(); } } while (0)
;
3325 // DecodeN could be pinned when it can't be fold into
3326 // an address expression, see the code for Op_CastPP above.
3327 assert(n->in(0) == NULL || (UseCompressedOops && !Matcher::narrow_oop_use_complex_address()), "no control")do { if (!(n->in(0) == __null || (UseCompressedOops &&
!Matcher::narrow_oop_use_complex_address()))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3327, "assert(" "n->in(0) == __null || (UseCompressedOops && !Matcher::narrow_oop_use_complex_address())"
") failed", "no control"); ::breakpoint(); } } while (0)
;
3328 break;
3329
3330 case Op_EncodeP:
3331 case Op_EncodePKlass: {
3332 Node* in1 = n->in(1);
3333 if (in1->is_DecodeNarrowPtr()) {
3334 n->subsume_by(in1->in(1), this);
3335 } else if (in1->Opcode() == Op_ConP) {
3336 const Type* t = in1->bottom_type();
3337 if (t == TypePtr::NULL_PTR) {
3338 assert(t->isa_oopptr(), "null klass?")do { if (!(t->isa_oopptr())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3338, "assert(" "t->isa_oopptr()" ") failed", "null klass?"
); ::breakpoint(); } } while (0)
;
3339 n->subsume_by(ConNode::make(TypeNarrowOop::NULL_PTR), this);
3340 } else if (t->isa_oopptr()) {
3341 n->subsume_by(ConNode::make(t->make_narrowoop()), this);
3342 } else if (t->isa_klassptr()) {
3343 n->subsume_by(ConNode::make(t->make_narrowklass()), this);
3344 }
3345 }
3346 if (in1->outcnt() == 0) {
3347 in1->disconnect_inputs(this);
3348 }
3349 break;
3350 }
3351
3352 case Op_Proj: {
3353 if (OptimizeStringConcat || IncrementalInline) {
3354 ProjNode* proj = n->as_Proj();
3355 if (proj->_is_io_use) {
3356 assert(proj->_con == TypeFunc::I_O || proj->_con == TypeFunc::Memory, "")do { if (!(proj->_con == TypeFunc::I_O || proj->_con ==
TypeFunc::Memory)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3356, "assert(" "proj->_con == TypeFunc::I_O || proj->_con == TypeFunc::Memory"
") failed", ""); ::breakpoint(); } } while (0)
;
3357 // Separate projections were used for the exception path which
3358 // are normally removed by a late inline. If it wasn't inlined
3359 // then they will hang around and should just be replaced with
3360 // the original one. Merge them.
3361 Node* non_io_proj = proj->in(0)->as_Multi()->proj_out_or_null(proj->_con, false /*is_io_use*/);
3362 if (non_io_proj != NULL__null) {
3363 proj->subsume_by(non_io_proj , this);
3364 }
3365 }
3366 }
3367 break;
3368 }
3369
3370 case Op_Phi:
3371 if (n->as_Phi()->bottom_type()->isa_narrowoop() || n->as_Phi()->bottom_type()->isa_narrowklass()) {
3372 // The EncodeP optimization may create Phi with the same edges
3373 // for all paths. It is not handled well by Register Allocator.
3374 Node* unique_in = n->in(1);
3375 assert(unique_in != NULL, "")do { if (!(unique_in != __null)) { (*g_assert_poison) = 'X';;
report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3375, "assert(" "unique_in != __null" ") failed", ""); ::breakpoint
(); } } while (0)
;
3376 uint cnt = n->req();
3377 for (uint i = 2; i < cnt; i++) {
3378 Node* m = n->in(i);
3379 assert(m != NULL, "")do { if (!(m != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3379, "assert(" "m != __null" ") failed", ""); ::breakpoint
(); } } while (0)
;
3380 if (unique_in != m)
3381 unique_in = NULL__null;
3382 }
3383 if (unique_in != NULL__null) {
3384 n->subsume_by(unique_in, this);
3385 }
3386 }
3387 break;
3388
3389#endif
3390
3391#ifdef ASSERT1
3392 case Op_CastII:
3393 // Verify that all range check dependent CastII nodes were removed.
3394 if (n->isa_CastII()->has_range_check()) {
3395 n->dump(3);
3396 assert(false, "Range check dependent CastII node was not removed")do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3396, "assert(" "false" ") failed", "Range check dependent CastII node was not removed"
); ::breakpoint(); } } while (0)
;
3397 }
3398 break;
3399#endif
3400
3401 case Op_ModI:
3402 if (UseDivMod) {
3403 // Check if a%b and a/b both exist
3404 Node* d = n->find_similar(Op_DivI);
3405 if (d) {
3406 // Replace them with a fused divmod if supported
3407 if (Matcher::has_match_rule(Op_DivModI)) {
3408 DivModINode* divmod = DivModINode::make(n);
3409 d->subsume_by(divmod->div_proj(), this);
3410 n->subsume_by(divmod->mod_proj(), this);
3411 } else {
3412 // replace a%b with a-((a/b)*b)
3413 Node* mult = new MulINode(d, d->in(2));
3414 Node* sub = new SubINode(d->in(1), mult);
3415 n->subsume_by(sub, this);
3416 }
3417 }
3418 }
3419 break;
3420
3421 case Op_ModL:
3422 if (UseDivMod) {
3423 // Check if a%b and a/b both exist
3424 Node* d = n->find_similar(Op_DivL);
3425 if (d) {
3426 // Replace them with a fused divmod if supported
3427 if (Matcher::has_match_rule(Op_DivModL)) {
3428 DivModLNode* divmod = DivModLNode::make(n);
3429 d->subsume_by(divmod->div_proj(), this);
3430 n->subsume_by(divmod->mod_proj(), this);
3431 } else {
3432 // replace a%b with a-((a/b)*b)
3433 Node* mult = new MulLNode(d, d->in(2));
3434 Node* sub = new SubLNode(d->in(1), mult);
3435 n->subsume_by(sub, this);
3436 }
3437 }
3438 }
3439 break;
3440
3441 case Op_LoadVector:
3442 case Op_StoreVector:
3443 case Op_LoadVectorGather:
3444 case Op_StoreVectorScatter:
3445 case Op_LoadVectorGatherMasked:
3446 case Op_StoreVectorScatterMasked:
3447 case Op_VectorCmpMasked:
3448 case Op_VectorMaskGen:
3449 case Op_LoadVectorMasked:
3450 case Op_StoreVectorMasked:
3451 break;
3452
3453 case Op_AddReductionVI:
3454 case Op_AddReductionVL:
3455 case Op_AddReductionVF:
3456 case Op_AddReductionVD:
3457 case Op_MulReductionVI:
3458 case Op_MulReductionVL:
3459 case Op_MulReductionVF:
3460 case Op_MulReductionVD:
3461 case Op_MinReductionV:
3462 case Op_MaxReductionV:
3463 case Op_AndReductionV:
3464 case Op_OrReductionV:
3465 case Op_XorReductionV:
3466 break;
3467
3468 case Op_PackB:
3469 case Op_PackS:
3470 case Op_PackI:
3471 case Op_PackF:
3472 case Op_PackL:
3473 case Op_PackD:
3474 if (n->req()-1 > 2) {
3475 // Replace many operand PackNodes with a binary tree for matching
3476 PackNode* p = (PackNode*) n;
3477 Node* btp = p->binary_tree_pack(1, n->req());
3478 n->subsume_by(btp, this);
3479 }
3480 break;
3481 case Op_Loop:
3482 assert(!n->as_Loop()->is_loop_nest_inner_loop() || _loop_opts_cnt == 0, "should have been turned into a counted loop")do { if (!(!n->as_Loop()->is_loop_nest_inner_loop() || _loop_opts_cnt
== 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3482, "assert(" "!n->as_Loop()->is_loop_nest_inner_loop() || _loop_opts_cnt == 0"
") failed", "should have been turned into a counted loop"); ::
breakpoint(); } } while (0)
;
3483 case Op_CountedLoop:
3484 case Op_LongCountedLoop:
3485 case Op_OuterStripMinedLoop:
3486 if (n->as_Loop()->is_inner_loop()) {
3487 frc.inc_inner_loop_count();
3488 }
3489 n->as_Loop()->verify_strip_mined(0);
3490 break;
3491 case Op_LShiftI:
3492 case Op_RShiftI:
3493 case Op_URShiftI:
3494 case Op_LShiftL:
3495 case Op_RShiftL:
3496 case Op_URShiftL:
3497 if (Matcher::need_masked_shift_count) {
3498 // The cpu's shift instructions don't restrict the count to the
3499 // lower 5/6 bits. We need to do the masking ourselves.
3500 Node* in2 = n->in(2);
3501 juint mask = (n->bottom_type() == TypeInt::INT) ? (BitsPerInt - 1) : (BitsPerLong - 1);
3502 const TypeInt* t = in2->find_int_type();
3503 if (t != NULL__null && t->is_con()) {
3504 juint shift = t->get_con();
3505 if (shift > mask) { // Unsigned cmp
3506 n->set_req(2, ConNode::make(TypeInt::make(shift & mask)));
3507 }
3508 } else {
3509 if (t == NULL__null || t->_lo < 0 || t->_hi > (int)mask) {
3510 Node* shift = new AndINode(in2, ConNode::make(TypeInt::make(mask)));
3511 n->set_req(2, shift);
3512 }
3513 }
3514 if (in2->outcnt() == 0) { // Remove dead node
3515 in2->disconnect_inputs(this);
3516 }
3517 }
3518 break;
3519 case Op_MemBarStoreStore:
3520 case Op_MemBarRelease:
3521 // Break the link with AllocateNode: it is no longer useful and
3522 // confuses register allocation.
3523 if (n->req() > MemBarNode::Precedent) {
3524 n->set_req(MemBarNode::Precedent, top());
3525 }
3526 break;
3527 case Op_MemBarAcquire: {
3528 if (n->as_MemBar()->trailing_load() && n->req() > MemBarNode::Precedent) {
3529 // At parse time, the trailing MemBarAcquire for a volatile load
3530 // is created with an edge to the load. After optimizations,
3531 // that input may be a chain of Phis. If those phis have no
3532 // other use, then the MemBarAcquire keeps them alive and
3533 // register allocation can be confused.
3534 ResourceMark rm;
3535 Unique_Node_List wq;
3536 wq.push(n->in(MemBarNode::Precedent));
3537 n->set_req(MemBarNode::Precedent, top());
3538 while (wq.size() > 0) {
3539 Node* m = wq.pop();
3540 if (m->outcnt() == 0) {
3541 for (uint j = 0; j < m->req(); j++) {
3542 Node* in = m->in(j);
3543 if (in != NULL__null) {
3544 wq.push(in);
3545 }
3546 }
3547 m->disconnect_inputs(this);
3548 }
3549 }
3550 }
3551 break;
3552 }
3553 case Op_Blackhole:
3554 break;
3555 case Op_RangeCheck: {
3556 RangeCheckNode* rc = n->as_RangeCheck();
3557 Node* iff = new IfNode(rc->in(0), rc->in(1), rc->_prob, rc->_fcnt);
3558 n->subsume_by(iff, this);
3559 frc._tests.push(iff);
3560 break;
3561 }
3562 case Op_ConvI2L: {
3563 if (!Matcher::convi2l_type_required) {
3564 // Code generation on some platforms doesn't need accurate
3565 // ConvI2L types. Widening the type can help remove redundant
3566 // address computations.
3567 n->as_Type()->set_type(TypeLong::INT);
3568 ResourceMark rm;
3569 Unique_Node_List wq;
3570 wq.push(n);
3571 for (uint next = 0; next < wq.size(); next++) {
3572 Node *m = wq.at(next);
3573
3574 for(;;) {
3575 // Loop over all nodes with identical inputs edges as m
3576 Node* k = m->find_similar(m->Opcode());
3577 if (k == NULL__null) {
3578 break;
3579 }
3580 // Push their uses so we get a chance to remove node made
3581 // redundant
3582 for (DUIterator_Fast imax, i = k->fast_outs(imax); i < imax; i++) {
3583 Node* u = k->fast_out(i);
3584 if (u->Opcode() == Op_LShiftL ||
3585 u->Opcode() == Op_AddL ||
3586 u->Opcode() == Op_SubL ||
3587 u->Opcode() == Op_AddP) {
3588 wq.push(u);
3589 }
3590 }
3591 // Replace all nodes with identical edges as m with m
3592 k->subsume_by(m, this);
3593 }
3594 }
3595 }
3596 break;
3597 }
3598 case Op_CmpUL: {
3599 if (!Matcher::has_match_rule(Op_CmpUL)) {
3600 // No support for unsigned long comparisons
3601 ConINode* sign_pos = new ConINode(TypeInt::make(BitsPerLong - 1));
3602 Node* sign_bit_mask = new RShiftLNode(n->in(1), sign_pos);
3603 Node* orl = new OrLNode(n->in(1), sign_bit_mask);
3604 ConLNode* remove_sign_mask = new ConLNode(TypeLong::make(max_jlong));
3605 Node* andl = new AndLNode(orl, remove_sign_mask);
3606 Node* cmp = new CmpLNode(andl, n->in(2));
3607 n->subsume_by(cmp, this);
3608 }
3609 break;
3610 }
3611 default:
3612 assert(!n->is_Call(), "")do { if (!(!n->is_Call())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3612, "assert(" "!n->is_Call()" ") failed", ""); ::breakpoint
(); } } while (0)
;
3613 assert(!n->is_Mem(), "")do { if (!(!n->is_Mem())) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3613, "assert(" "!n->is_Mem()" ") failed", ""); ::breakpoint
(); } } while (0)
;
3614 assert(nop != Op_ProfileBoolean, "should be eliminated during IGVN")do { if (!(nop != Op_ProfileBoolean)) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3614, "assert(" "nop != Op_ProfileBoolean" ") failed", "should be eliminated during IGVN"
); ::breakpoint(); } } while (0)
;
3615 break;
3616 }
3617}
3618
3619//------------------------------final_graph_reshaping_walk---------------------
3620// Replacing Opaque nodes with their input in final_graph_reshaping_impl(),
3621// requires that the walk visits a node's inputs before visiting the node.
3622void Compile::final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &frc ) {
3623 Unique_Node_List sfpt;
3624
3625 frc._visited.set(root->_idx); // first, mark node as visited
3626 uint cnt = root->req();
3627 Node *n = root;
3628 uint i = 0;
3629 while (true) {
3630 if (i < cnt) {
3631 // Place all non-visited non-null inputs onto stack
3632 Node* m = n->in(i);
3633 ++i;
3634 if (m != NULL__null && !frc._visited.test_set(m->_idx)) {
3635 if (m->is_SafePoint() && m->as_SafePoint()->jvms() != NULL__null) {
3636 // compute worst case interpreter size in case of a deoptimization
3637 update_interpreter_frame_size(m->as_SafePoint()->jvms()->interpreter_frame_size());
3638
3639 sfpt.push(m);
3640 }
3641 cnt = m->req();
3642 nstack.push(n, i); // put on stack parent and next input's index
3643 n = m;
3644 i = 0;
3645 }
3646 } else {
3647 // Now do post-visit work
3648 final_graph_reshaping_impl( n, frc );
3649 if (nstack.is_empty())
3650 break; // finished
3651 n = nstack.node(); // Get node from stack
3652 cnt = n->req();
3653 i = nstack.index();
3654 nstack.pop(); // Shift to the next node on stack
3655 }
3656 }
3657
3658 // Skip next transformation if compressed oops are not used.
3659 if ((UseCompressedOops && !Matcher::gen_narrow_oop_implicit_null_checks()) ||
3660 (!UseCompressedOops && !UseCompressedClassPointers))
3661 return;
3662
3663 // Go over safepoints nodes to skip DecodeN/DecodeNKlass nodes for debug edges.
3664 // It could be done for an uncommon traps or any safepoints/calls
3665 // if the DecodeN/DecodeNKlass node is referenced only in a debug info.
3666 while (sfpt.size() > 0) {
3667 n = sfpt.pop();
3668 JVMState *jvms = n->as_SafePoint()->jvms();
3669 assert(jvms != NULL, "sanity")do { if (!(jvms != __null)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3669, "assert(" "jvms != __null" ") failed", "sanity"); ::breakpoint
(); } } while (0)
;
3670 int start = jvms->debug_start();
3671 int end = n->req();
3672 bool is_uncommon = (n->is_CallStaticJava() &&
3673 n->as_CallStaticJava()->uncommon_trap_request() != 0);
3674 for (int j = start; j < end; j++) {
3675 Node* in = n->in(j);
3676 if (in->is_DecodeNarrowPtr()) {
3677 bool safe_to_skip = true;
3678 if (!is_uncommon ) {
3679 // Is it safe to skip?
3680 for (uint i = 0; i < in->outcnt(); i++) {
3681 Node* u = in->raw_out(i);
3682 if (!u->is_SafePoint() ||
3683 (u->is_Call() && u->as_Call()->has_non_debug_use(n))) {
3684 safe_to_skip = false;
3685 }
3686 }
3687 }
3688 if (safe_to_skip) {
3689 n->set_req(j, in->in(1));
3690 }
3691 if (in->outcnt() == 0) {
3692 in->disconnect_inputs(this);
3693 }
3694 }
3695 }
3696 }
3697}
3698
3699//------------------------------final_graph_reshaping--------------------------
3700// Final Graph Reshaping.
3701//
3702// (1) Clone simple inputs to uncommon calls, so they can be scheduled late
3703// and not commoned up and forced early. Must come after regular
3704// optimizations to avoid GVN undoing the cloning. Clone constant
3705// inputs to Loop Phis; these will be split by the allocator anyways.
3706// Remove Opaque nodes.
3707// (2) Move last-uses by commutative operations to the left input to encourage
3708// Intel update-in-place two-address operations and better register usage
3709// on RISCs. Must come after regular optimizations to avoid GVN Ideal
3710// calls canonicalizing them back.
3711// (3) Count the number of double-precision FP ops, single-precision FP ops
3712// and call sites. On Intel, we can get correct rounding either by
3713// forcing singles to memory (requires extra stores and loads after each
3714// FP bytecode) or we can set a rounding mode bit (requires setting and
3715// clearing the mode bit around call sites). The mode bit is only used
3716// if the relative frequency of single FP ops to calls is low enough.
3717// This is a key transform for SPEC mpeg_audio.
3718// (4) Detect infinite loops; blobs of code reachable from above but not
3719// below. Several of the Code_Gen algorithms fail on such code shapes,
3720// so we simply bail out. Happens a lot in ZKM.jar, but also happens
3721// from time to time in other codes (such as -Xcomp finalizer loops, etc).
3722// Detection is by looking for IfNodes where only 1 projection is
3723// reachable from below or CatchNodes missing some targets.
3724// (5) Assert for insane oop offsets in debug mode.
3725
3726bool Compile::final_graph_reshaping() {
3727 // an infinite loop may have been eliminated by the optimizer,
3728 // in which case the graph will be empty.
3729 if (root()->req() == 1) {
3730 record_method_not_compilable("trivial infinite loop");
3731 return true;
3732 }
3733
3734 // Expensive nodes have their control input set to prevent the GVN
3735 // from freely commoning them. There's no GVN beyond this point so
3736 // no need to keep the control input. We want the expensive nodes to
3737 // be freely moved to the least frequent code path by gcm.
3738 assert(OptimizeExpensiveOps || expensive_count() == 0, "optimization off but list non empty?")do { if (!(OptimizeExpensiveOps || expensive_count() == 0)) {
(*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3738, "assert(" "OptimizeExpensiveOps || expensive_count() == 0"
") failed", "optimization off but list non empty?"); ::breakpoint
(); } } while (0)
;
3739 for (int i = 0; i < expensive_count(); i++) {
3740 _expensive_nodes.at(i)->set_req(0, NULL__null);
3741 }
3742
3743 Final_Reshape_Counts frc;
3744
3745 // Visit everybody reachable!
3746 // Allocate stack of size C->live_nodes()/2 to avoid frequent realloc
3747 Node_Stack nstack(live_nodes() >> 1);
3748 final_graph_reshaping_walk(nstack, root(), frc);
3749
3750 // Check for unreachable (from below) code (i.e., infinite loops).
3751 for( uint i = 0; i < frc._tests.size(); i++ ) {
3752 MultiBranchNode *n = frc._tests[i]->as_MultiBranch();
3753 // Get number of CFG targets.
3754 // Note that PCTables include exception targets after calls.
3755 uint required_outcnt = n->required_outcnt();
3756 if (n->outcnt() != required_outcnt) {
3757 // Check for a few special cases. Rethrow Nodes never take the
3758 // 'fall-thru' path, so expected kids is 1 less.
3759 if (n->is_PCTable() && n->in(0) && n->in(0)->in(0)) {
3760 if (n->in(0)->in(0)->is_Call()) {
3761 CallNode *call = n->in(0)->in(0)->as_Call();
3762 if (call->entry_point() == OptoRuntime::rethrow_stub()) {
3763 required_outcnt--; // Rethrow always has 1 less kid
3764 } else if (call->req() > TypeFunc::Parms &&
3765 call->is_CallDynamicJava()) {
3766 // Check for null receiver. In such case, the optimizer has
3767 // detected that the virtual call will always result in a null
3768 // pointer exception. The fall-through projection of this CatchNode
3769 // will not be populated.
3770 Node *arg0 = call->in(TypeFunc::Parms);
3771 if (arg0->is_Type() &&
3772 arg0->as_Type()->type()->higher_equal(TypePtr::NULL_PTR)) {
3773 required_outcnt--;
3774 }
3775 } else if (call->entry_point() == OptoRuntime::new_array_Java() &&
3776 call->req() > TypeFunc::Parms+1 &&
3777 call->is_CallStaticJava()) {
3778 // Check for negative array length. In such case, the optimizer has
3779 // detected that the allocation attempt will always result in an
3780 // exception. There is no fall-through projection of this CatchNode .
3781 Node *arg1 = call->in(TypeFunc::Parms+1);
3782 if (arg1->is_Type() &&
3783 arg1->as_Type()->type()->join(TypeInt::POS)->empty()) {
3784 required_outcnt--;
3785 }
3786 }
3787 }
3788 }
3789 // Recheck with a better notion of 'required_outcnt'
3790 if (n->outcnt() != required_outcnt) {
3791 record_method_not_compilable("malformed control flow");
3792 return true; // Not all targets reachable!
3793 }
3794 }
3795 // Check that I actually visited all kids. Unreached kids
3796 // must be infinite loops.
3797 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++)
3798 if (!frc._visited.test(n->fast_out(j)->_idx)) {
3799 record_method_not_compilable("infinite loop");
3800 return true; // Found unvisited kid; must be unreach
3801 }
3802
3803 // Here so verification code in final_graph_reshaping_walk()
3804 // always see an OuterStripMinedLoopEnd
3805 if (n->is_OuterStripMinedLoopEnd() || n->is_LongCountedLoopEnd()) {
3806 IfNode* init_iff = n->as_If();
3807 Node* iff = new IfNode(init_iff->in(0), init_iff->in(1), init_iff->_prob, init_iff->_fcnt);
3808 n->subsume_by(iff, this);
3809 }
3810 }
3811
3812#ifdef IA32
3813 // If original bytecodes contained a mixture of floats and doubles
3814 // check if the optimizer has made it homogenous, item (3).
3815 if (UseSSE == 0 &&
3816 frc.get_float_count() > 32 &&
3817 frc.get_double_count() == 0 &&
3818 (10 * frc.get_call_count() < frc.get_float_count()) ) {
3819 set_24_bit_selection_and_mode(false, true);
3820 }
3821#endif // IA32
3822
3823 set_java_calls(frc.get_java_call_count());
3824 set_inner_loops(frc.get_inner_loop_count());
3825
3826 // No infinite loops, no reason to bail out.
3827 return false;
3828}
3829
3830//-----------------------------too_many_traps----------------------------------
3831// Report if there are too many traps at the current method and bci.
3832// Return true if there was a trap, and/or PerMethodTrapLimit is exceeded.
3833bool Compile::too_many_traps(ciMethod* method,
3834 int bci,
3835 Deoptimization::DeoptReason reason) {
3836 ciMethodData* md = method->method_data();
3837 if (md->is_empty()) {
3838 // Assume the trap has not occurred, or that it occurred only
3839 // because of a transient condition during start-up in the interpreter.
3840 return false;
3841 }
3842 ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : NULL__null;
3843 if (md->has_trap_at(bci, m, reason) != 0) {
3844 // Assume PerBytecodeTrapLimit==0, for a more conservative heuristic.
3845 // Also, if there are multiple reasons, or if there is no per-BCI record,
3846 // assume the worst.
3847 if (log())
3848 log()->elem("observe trap='%s' count='%d'",
3849 Deoptimization::trap_reason_name(reason),
3850 md->trap_count(reason));
3851 return true;
3852 } else {
3853 // Ignore method/bci and see if there have been too many globally.
3854 return too_many_traps(reason, md);
3855 }
3856}
3857
3858// Less-accurate variant which does not require a method and bci.
3859bool Compile::too_many_traps(Deoptimization::DeoptReason reason,
3860 ciMethodData* logmd) {
3861 if (trap_count(reason) >= Deoptimization::per_method_trap_limit(reason)) {
3862 // Too many traps globally.
3863 // Note that we use cumulative trap_count, not just md->trap_count.
3864 if (log()) {
3865 int mcount = (logmd == NULL__null)? -1: (int)logmd->trap_count(reason);
3866 log()->elem("observe trap='%s' count='0' mcount='%d' ccount='%d'",
3867 Deoptimization::trap_reason_name(reason),
3868 mcount, trap_count(reason));
3869 }
3870 return true;
3871 } else {
3872 // The coast is clear.
3873 return false;
3874 }
3875}
3876
3877//--------------------------too_many_recompiles--------------------------------
3878// Report if there are too many recompiles at the current method and bci.
3879// Consults PerBytecodeRecompilationCutoff and PerMethodRecompilationCutoff.
3880// Is not eager to return true, since this will cause the compiler to use
3881// Action_none for a trap point, to avoid too many recompilations.
3882bool Compile::too_many_recompiles(ciMethod* method,
3883 int bci,
3884 Deoptimization::DeoptReason reason) {
3885 ciMethodData* md = method->method_data();
3886 if (md->is_empty()) {
3887 // Assume the trap has not occurred, or that it occurred only
3888 // because of a transient condition during start-up in the interpreter.
3889 return false;
3890 }
3891 // Pick a cutoff point well within PerBytecodeRecompilationCutoff.
3892 uint bc_cutoff = (uint) PerBytecodeRecompilationCutoff / 8;
3893 uint m_cutoff = (uint) PerMethodRecompilationCutoff / 2 + 1; // not zero
3894 Deoptimization::DeoptReason per_bc_reason
3895 = Deoptimization::reason_recorded_per_bytecode_if_any(reason);
3896 ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : NULL__null;
3897 if ((per_bc_reason == Deoptimization::Reason_none
3898 || md->has_trap_at(bci, m, reason) != 0)
3899 // The trap frequency measure we care about is the recompile count:
3900 && md->trap_recompiled_at(bci, m)
3901 && md->overflow_recompile_count() >= bc_cutoff) {
3902 // Do not emit a trap here if it has already caused recompilations.
3903 // Also, if there are multiple reasons, or if there is no per-BCI record,
3904 // assume the worst.
3905 if (log())
3906 log()->elem("observe trap='%s recompiled' count='%d' recompiles2='%d'",
3907 Deoptimization::trap_reason_name(reason),
3908 md->trap_count(reason),
3909 md->overflow_recompile_count());
3910 return true;
3911 } else if (trap_count(reason) != 0
3912 && decompile_count() >= m_cutoff) {
3913 // Too many recompiles globally, and we have seen this sort of trap.
3914 // Use cumulative decompile_count, not just md->decompile_count.
3915 if (log())
3916 log()->elem("observe trap='%s' count='%d' mcount='%d' decompiles='%d' mdecompiles='%d'",
3917 Deoptimization::trap_reason_name(reason),
3918 md->trap_count(reason), trap_count(reason),
3919 md->decompile_count(), decompile_count());
3920 return true;
3921 } else {
3922 // The coast is clear.
3923 return false;
3924 }
3925}
3926
3927// Compute when not to trap. Used by matching trap based nodes and
3928// NullCheck optimization.
3929void Compile::set_allowed_deopt_reasons() {
3930 _allowed_reasons = 0;
3931 if (is_method_compilation()) {
3932 for (int rs = (int)Deoptimization::Reason_none+1; rs < Compile::trapHistLength; rs++) {
3933 assert(rs < BitsPerInt, "recode bit map")do { if (!(rs < BitsPerInt)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 3933, "assert(" "rs < BitsPerInt" ") failed", "recode bit map"
); ::breakpoint(); } } while (0)
;
3934 if (!too_many_traps((Deoptimization::DeoptReason) rs)) {
3935 _allowed_reasons |= nth_bit(rs)(((rs) >= BitsPerWord) ? 0 : (OneBit << (rs)));
3936 }
3937 }
3938 }
3939}
3940
3941bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
3942 return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
3943}
3944
3945bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
3946 return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
3947}
3948
3949bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
3950 if (holder->is_initialized()) {
3951 return false;
3952 }
3953 if (holder->is_being_initialized()) {
3954 if (accessing_method->holder() == holder) {
3955 // Access inside a class. The barrier can be elided when access happens in <clinit>,
3956 // <init>, or a static method. In all those cases, there was an initialization
3957 // barrier on the holder klass passed.
3958 if (accessing_method->is_static_initializer() ||
3959 accessing_method->is_object_initializer() ||
3960 accessing_method->is_static()) {
3961 return false;
3962 }
3963 } else if (accessing_method->holder()->is_subclass_of(holder)) {
3964 // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
3965 // In case of <init> or a static method, the barrier is on the subclass is not enough:
3966 // child class can become fully initialized while its parent class is still being initialized.
3967 if (accessing_method->is_static_initializer()) {
3968 return false;
3969 }
3970 }
3971 ciMethod* root = method(); // the root method of compilation
3972 if (root != accessing_method) {
3973 return needs_clinit_barrier(holder, root); // check access in the context of compilation root
3974 }
3975 }
3976 return true;
3977}
3978
3979#ifndef PRODUCT
3980//------------------------------verify_graph_edges---------------------------
3981// Walk the Graph and verify that there is a one-to-one correspondence
3982// between Use-Def edges and Def-Use edges in the graph.
3983void Compile::verify_graph_edges(bool no_dead_code) {
3984 if (VerifyGraphEdges) {
3985 Unique_Node_List visited;
3986 // Call recursive graph walk to check edges
3987 _root->verify_edges(visited);
3988 if (no_dead_code) {
3989 // Now make sure that no visited node is used by an unvisited node.
3990 bool dead_nodes = false;
3991 Unique_Node_List checked;
3992 while (visited.size() > 0) {
3993 Node* n = visited.pop();
3994 checked.push(n);
3995 for (uint i = 0; i < n->outcnt(); i++) {
3996 Node* use = n->raw_out(i);
3997 if (checked.member(use)) continue; // already checked
3998 if (visited.member(use)) continue; // already in the graph
3999 if (use->is_Con()) continue; // a dead ConNode is OK
4000 // At this point, we have found a dead node which is DU-reachable.
4001 if (!dead_nodes) {
4002 tty->print_cr("*** Dead nodes reachable via DU edges:");
4003 dead_nodes = true;
4004 }
4005 use->dump(2);
4006 tty->print_cr("---");
4007 checked.push(use); // No repeats; pretend it is now checked.
4008 }
4009 }
4010 assert(!dead_nodes, "using nodes must be reachable from root")do { if (!(!dead_nodes)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4010, "assert(" "!dead_nodes" ") failed", "using nodes must be reachable from root"
); ::breakpoint(); } } while (0)
;
4011 }
4012 }
4013}
4014#endif
4015
4016// The Compile object keeps track of failure reasons separately from the ciEnv.
4017// This is required because there is not quite a 1-1 relation between the
4018// ciEnv and its compilation task and the Compile object. Note that one
4019// ciEnv might use two Compile objects, if C2Compiler::compile_method decides
4020// to backtrack and retry without subsuming loads. Other than this backtracking
4021// behavior, the Compile's failure reason is quietly copied up to the ciEnv
4022// by the logic in C2Compiler.
4023void Compile::record_failure(const char* reason) {
4024 if (log() != NULL__null) {
4025 log()->elem("failure reason='%s' phase='compile'", reason);
4026 }
4027 if (_failure_reason == NULL__null) {
4028 // Record the first failure reason.
4029 _failure_reason = reason;
4030 }
4031
4032 if (!C->failure_reason_is(C2Compiler::retry_no_subsuming_loads())) {
4033 C->print_method(PHASE_FAILURE);
4034 }
4035 _root = NULL__null; // flush the graph, too
4036}
4037
4038Compile::TracePhase::TracePhase(const char* name, elapsedTimer* accumulator)
4039 : TraceTime(name, accumulator, CITime, CITimeVerbose),
4040 _phase_name(name), _dolog(CITimeVerbose)
4041{
4042 if (_dolog) {
4043 C = Compile::current();
4044 _log = C->log();
4045 } else {
4046 C = NULL__null;
4047 _log = NULL__null;
4048 }
4049 if (_log != NULL__null) {
4050 _log->begin_head("phase name='%s' nodes='%d' live='%d'", _phase_name, C->unique(), C->live_nodes());
4051 _log->stamp();
4052 _log->end_head();
4053 }
4054}
4055
4056Compile::TracePhase::~TracePhase() {
4057
4058 C = Compile::current();
4059 if (_dolog) {
4060 _log = C->log();
4061 } else {
4062 _log = NULL__null;
4063 }
4064
4065#ifdef ASSERT1
4066 if (PrintIdealNodeCount) {
4067 tty->print_cr("phase name='%s' nodes='%d' live='%d' live_graph_walk='%d'",
4068 _phase_name, C->unique(), C->live_nodes(), C->count_live_nodes_by_graph_walk());
4069 }
4070
4071 if (VerifyIdealNodeCount) {
4072 Compile::current()->print_missing_nodes();
4073 }
4074#endif
4075
4076 if (_log != NULL__null) {
4077 _log->done("phase name='%s' nodes='%d' live='%d'", _phase_name, C->unique(), C->live_nodes());
4078 }
4079}
4080
4081//----------------------------static_subtype_check-----------------------------
4082// Shortcut important common cases when superklass is exact:
4083// (0) superklass is java.lang.Object (can occur in reflective code)
4084// (1) subklass is already limited to a subtype of superklass => always ok
4085// (2) subklass does not overlap with superklass => always fail
4086// (3) superklass has NO subtypes and we can check with a simple compare.
4087int Compile::static_subtype_check(ciKlass* superk, ciKlass* subk) {
4088 if (StressReflectiveCode) {
4089 return SSC_full_test; // Let caller generate the general case.
4090 }
4091
4092 if (superk == env()->Object_klass()) {
4093 return SSC_always_true; // (0) this test cannot fail
4094 }
4095
4096 ciType* superelem = superk;
4097 ciType* subelem = subk;
4098 if (superelem->is_array_klass()) {
4099 superelem = superelem->as_array_klass()->base_element_type();
4100 }
4101 if (subelem->is_array_klass()) {
4102 subelem = subelem->as_array_klass()->base_element_type();
4103 }
4104
4105 if (!subk->is_interface()) { // cannot trust static interface types yet
4106 if (subk->is_subtype_of(superk)) {
4107 return SSC_always_true; // (1) false path dead; no dynamic test needed
4108 }
4109 if (!(superelem->is_klass() && superelem->as_klass()->is_interface()) &&
4110 !(subelem->is_klass() && subelem->as_klass()->is_interface()) &&
4111 !superk->is_subtype_of(subk)) {
4112 return SSC_always_false; // (2) true path dead; no dynamic test needed
4113 }
4114 }
4115
4116 // If casting to an instance klass, it must have no subtypes
4117 if (superk->is_interface()) {
4118 // Cannot trust interfaces yet.
4119 // %%% S.B. superk->nof_implementors() == 1
4120 } else if (superelem->is_instance_klass()) {
4121 ciInstanceKlass* ik = superelem->as_instance_klass();
4122 if (!ik->has_subklass() && !ik->is_interface()) {
4123 if (!ik->is_final()) {
4124 // Add a dependency if there is a chance of a later subclass.
4125 dependencies()->assert_leaf_type(ik);
4126 }
4127 return SSC_easy_test; // (3) caller can do a simple ptr comparison
4128 }
4129 } else {
4130 // A primitive array type has no subtypes.
4131 return SSC_easy_test; // (3) caller can do a simple ptr comparison
4132 }
4133
4134 return SSC_full_test;
4135}
4136
4137Node* Compile::conv_I2X_index(PhaseGVN* phase, Node* idx, const TypeInt* sizetype, Node* ctrl) {
4138#ifdef _LP641
4139 // The scaled index operand to AddP must be a clean 64-bit value.
4140 // Java allows a 32-bit int to be incremented to a negative
4141 // value, which appears in a 64-bit register as a large
4142 // positive number. Using that large positive number as an
4143 // operand in pointer arithmetic has bad consequences.
4144 // On the other hand, 32-bit overflow is rare, and the possibility
4145 // can often be excluded, if we annotate the ConvI2L node with
4146 // a type assertion that its value is known to be a small positive
4147 // number. (The prior range check has ensured this.)
4148 // This assertion is used by ConvI2LNode::Ideal.
4149 int index_max = max_jint - 1; // array size is max_jint, index is one less
4150 if (sizetype != NULL__null) index_max = sizetype->_hi - 1;
4151 const TypeInt* iidxtype = TypeInt::make(0, index_max, Type::WidenMax);
4152 idx = constrained_convI2L(phase, idx, iidxtype, ctrl);
4153#endif
4154 return idx;
4155}
4156
4157// Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
4158Node* Compile::constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl, bool carry_dependency) {
4159 if (ctrl != NULL__null) {
4160 // Express control dependency by a CastII node with a narrow type.
4161 value = new CastIINode(value, itype, carry_dependency ? ConstraintCastNode::StrongDependency : ConstraintCastNode::RegularDependency, true /* range check dependency */);
4162 // Make the CastII node dependent on the control input to prevent the narrowed ConvI2L
4163 // node from floating above the range check during loop optimizations. Otherwise, the
4164 // ConvI2L node may be eliminated independently of the range check, causing the data path
4165 // to become TOP while the control path is still there (although it's unreachable).
4166 value->set_req(0, ctrl);
4167 value = phase->transform(value);
4168 }
4169 const TypeLong* ltype = TypeLong::make(itype->_lo, itype->_hi, itype->_widen);
4170 return phase->transform(new ConvI2LNode(value, ltype));
4171}
4172
4173void Compile::print_inlining_stream_free() {
4174 if (_print_inlining_stream != NULL__null) {
4175 _print_inlining_stream->~stringStream();
4176 _print_inlining_stream = NULL__null;
4177 }
4178}
4179
4180// The message about the current inlining is accumulated in
4181// _print_inlining_stream and transfered into the _print_inlining_list
4182// once we know whether inlining succeeds or not. For regular
4183// inlining, messages are appended to the buffer pointed by
4184// _print_inlining_idx in the _print_inlining_list. For late inlining,
4185// a new buffer is added after _print_inlining_idx in the list. This
4186// way we can update the inlining message for late inlining call site
4187// when the inlining is attempted again.
4188void Compile::print_inlining_init() {
4189 if (print_inlining() || print_intrinsics()) {
4190 // print_inlining_init is actually called several times.
4191 print_inlining_stream_free();
4192 _print_inlining_stream = new stringStream();
4193 _print_inlining_list = new (comp_arena())GrowableArray<PrintInliningBuffer*>(comp_arena(), 1, 1, new PrintInliningBuffer());
4194 }
4195}
4196
4197void Compile::print_inlining_reinit() {
4198 if (print_inlining() || print_intrinsics()) {
4199 print_inlining_stream_free();
4200 // Re allocate buffer when we change ResourceMark
4201 _print_inlining_stream = new stringStream();
4202 }
4203}
4204
4205void Compile::print_inlining_reset() {
4206 _print_inlining_stream->reset();
4207}
4208
4209void Compile::print_inlining_commit() {
4210 assert(print_inlining() || print_intrinsics(), "PrintInlining off?")do { if (!(print_inlining() || print_intrinsics())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4210, "assert(" "print_inlining() || print_intrinsics()" ") failed"
, "PrintInlining off?"); ::breakpoint(); } } while (0)
;
4211 // Transfer the message from _print_inlining_stream to the current
4212 // _print_inlining_list buffer and clear _print_inlining_stream.
4213 _print_inlining_list->at(_print_inlining_idx)->ss()->write(_print_inlining_stream->base(), _print_inlining_stream->size());
4214 print_inlining_reset();
4215}
4216
4217void Compile::print_inlining_push() {
4218 // Add new buffer to the _print_inlining_list at current position
4219 _print_inlining_idx++;
4220 _print_inlining_list->insert_before(_print_inlining_idx, new PrintInliningBuffer());
4221}
4222
4223Compile::PrintInliningBuffer* Compile::print_inlining_current() {
4224 return _print_inlining_list->at(_print_inlining_idx);
4225}
4226
4227void Compile::print_inlining_update(CallGenerator* cg) {
4228 if (print_inlining() || print_intrinsics()) {
4229 if (cg->is_late_inline()) {
4230 if (print_inlining_current()->cg() != cg &&
4231 (print_inlining_current()->cg() != NULL__null ||
4232 print_inlining_current()->ss()->size() != 0)) {
4233 print_inlining_push();
4234 }
4235 print_inlining_commit();
4236 print_inlining_current()->set_cg(cg);
4237 } else {
4238 if (print_inlining_current()->cg() != NULL__null) {
4239 print_inlining_push();
4240 }
4241 print_inlining_commit();
4242 }
4243 }
4244}
4245
4246void Compile::print_inlining_move_to(CallGenerator* cg) {
4247 // We resume inlining at a late inlining call site. Locate the
4248 // corresponding inlining buffer so that we can update it.
4249 if (print_inlining() || print_intrinsics()) {
4250 for (int i = 0; i < _print_inlining_list->length(); i++) {
4251 if (_print_inlining_list->at(i)->cg() == cg) {
4252 _print_inlining_idx = i;
4253 return;
4254 }
4255 }
4256 ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here(
"/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4256); ::breakpoint(); } while (0)
;
4257 }
4258}
4259
4260void Compile::print_inlining_update_delayed(CallGenerator* cg) {
4261 if (print_inlining() || print_intrinsics()) {
4262 assert(_print_inlining_stream->size() > 0, "missing inlining msg")do { if (!(_print_inlining_stream->size() > 0)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4262, "assert(" "_print_inlining_stream->size() > 0" ") failed"
, "missing inlining msg"); ::breakpoint(); } } while (0)
;
4263 assert(print_inlining_current()->cg() == cg, "wrong entry")do { if (!(print_inlining_current()->cg() == cg)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4263, "assert(" "print_inlining_current()->cg() == cg" ") failed"
, "wrong entry"); ::breakpoint(); } } while (0)
;
4264 // replace message with new message
4265 _print_inlining_list->at_put(_print_inlining_idx, new PrintInliningBuffer());
4266 print_inlining_commit();
4267 print_inlining_current()->set_cg(cg);
4268 }
4269}
4270
4271void Compile::print_inlining_assert_ready() {
4272 assert(!_print_inlining || _print_inlining_stream->size() == 0, "loosing data")do { if (!(!_print_inlining || _print_inlining_stream->size
() == 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4272, "assert(" "!_print_inlining || _print_inlining_stream->size() == 0"
") failed", "loosing data"); ::breakpoint(); } } while (0)
;
4273}
4274
4275void Compile::process_print_inlining() {
4276 assert(_late_inlines.length() == 0, "not drained yet")do { if (!(_late_inlines.length() == 0)) { (*g_assert_poison)
= 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4276, "assert(" "_late_inlines.length() == 0" ") failed", "not drained yet"
); ::breakpoint(); } } while (0)
;
4277 if (print_inlining() || print_intrinsics()) {
4278 ResourceMark rm;
4279 stringStream ss;
4280 assert(_print_inlining_list != NULL, "process_print_inlining should be called only once.")do { if (!(_print_inlining_list != __null)) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4280, "assert(" "_print_inlining_list != __null" ") failed"
, "process_print_inlining should be called only once."); ::breakpoint
(); } } while (0)
;
4281 for (int i = 0; i < _print_inlining_list->length(); i++) {
4282 PrintInliningBuffer* pib = _print_inlining_list->at(i);
4283 ss.print("%s", pib->ss()->as_string());
4284 delete pib;
4285 DEBUG_ONLY(_print_inlining_list->at_put(i, NULL))_print_inlining_list->at_put(i, __null);
4286 }
4287 // Reset _print_inlining_list, it only contains destructed objects.
4288 // It is on the arena, so it will be freed when the arena is reset.
4289 _print_inlining_list = NULL__null;
4290 // _print_inlining_stream won't be used anymore, either.
4291 print_inlining_stream_free();
4292 size_t end = ss.size();
4293 _print_inlining_output = NEW_ARENA_ARRAY(comp_arena(), char, end+1)(char*) (comp_arena())->Amalloc((end+1) * sizeof(char));
4294 strncpy(_print_inlining_output, ss.base(), end+1);
4295 _print_inlining_output[end] = 0;
4296 }
4297}
4298
4299void Compile::dump_print_inlining() {
4300 if (_print_inlining_output != NULL__null) {
4301 tty->print_raw(_print_inlining_output);
4302 }
4303}
4304
4305void Compile::log_late_inline(CallGenerator* cg) {
4306 if (log() != NULL__null) {
4307 log()->head("late_inline method='%d' inline_id='" JLONG_FORMAT"%" "l" "d" "'", log()->identify(cg->method()),
4308 cg->unique_id());
4309 JVMState* p = cg->call_node()->jvms();
4310 while (p != NULL__null) {
4311 log()->elem("jvms bci='%d' method='%d'", p->bci(), log()->identify(p->method()));
4312 p = p->caller();
4313 }
4314 log()->tail("late_inline");
4315 }
4316}
4317
4318void Compile::log_late_inline_failure(CallGenerator* cg, const char* msg) {
4319 log_late_inline(cg);
4320 if (log() != NULL__null) {
4321 log()->inline_fail(msg);
4322 }
4323}
4324
4325void Compile::log_inline_id(CallGenerator* cg) {
4326 if (log() != NULL__null) {
4327 // The LogCompilation tool needs a unique way to identify late
4328 // inline call sites. This id must be unique for this call site in
4329 // this compilation. Try to have it unique across compilations as
4330 // well because it can be convenient when grepping through the log
4331 // file.
4332 // Distinguish OSR compilations from others in case CICountOSR is
4333 // on.
4334 jlong id = ((jlong)unique()) + (((jlong)compile_id()) << 33) + (CICountOSR && is_osr_compilation() ? ((jlong)1) << 32 : 0);
4335 cg->set_unique_id(id);
4336 log()->elem("inline_id id='" JLONG_FORMAT"%" "l" "d" "'", id);
4337 }
4338}
4339
4340void Compile::log_inline_failure(const char* msg) {
4341 if (C->log() != NULL__null) {
4342 C->log()->inline_fail(msg);
4343 }
4344}
4345
4346
4347// Dump inlining replay data to the stream.
4348// Don't change thread state and acquire any locks.
4349void Compile::dump_inline_data(outputStream* out) {
4350 InlineTree* inl_tree = ilt();
4351 if (inl_tree != NULL__null) {
4352 out->print(" inline %d", inl_tree->count());
4353 inl_tree->dump_replay_data(out);
4354 }
4355}
4356
4357int Compile::cmp_expensive_nodes(Node* n1, Node* n2) {
4358 if (n1->Opcode() < n2->Opcode()) return -1;
4359 else if (n1->Opcode() > n2->Opcode()) return 1;
4360
4361 assert(n1->req() == n2->req(), "can't compare %s nodes: n1->req() = %d, n2->req() = %d", NodeClassNames[n1->Opcode()], n1->req(), n2->req())do { if (!(n1->req() == n2->req())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4361, "assert(" "n1->req() == n2->req()" ") failed", "can't compare %s nodes: n1->req() = %d, n2->req() = %d"
, NodeClassNames[n1->Opcode()], n1->req(), n2->req()
); ::breakpoint(); } } while (0)
;
4362 for (uint i = 1; i < n1->req(); i++) {
4363 if (n1->in(i) < n2->in(i)) return -1;
4364 else if (n1->in(i) > n2->in(i)) return 1;
4365 }
4366
4367 return 0;
4368}
4369
4370int Compile::cmp_expensive_nodes(Node** n1p, Node** n2p) {
4371 Node* n1 = *n1p;
4372 Node* n2 = *n2p;
4373
4374 return cmp_expensive_nodes(n1, n2);
4375}
4376
4377void Compile::sort_expensive_nodes() {
4378 if (!expensive_nodes_sorted()) {
4379 _expensive_nodes.sort(cmp_expensive_nodes);
4380 }
4381}
4382
4383bool Compile::expensive_nodes_sorted() const {
4384 for (int i = 1; i < _expensive_nodes.length(); i++) {
4385 if (cmp_expensive_nodes(_expensive_nodes.adr_at(i), _expensive_nodes.adr_at(i-1)) < 0) {
4386 return false;
4387 }
4388 }
4389 return true;
4390}
4391
4392bool Compile::should_optimize_expensive_nodes(PhaseIterGVN &igvn) {
4393 if (_expensive_nodes.length() == 0) {
4394 return false;
4395 }
4396
4397 assert(OptimizeExpensiveOps, "optimization off?")do { if (!(OptimizeExpensiveOps)) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4397, "assert(" "OptimizeExpensiveOps" ") failed", "optimization off?"
); ::breakpoint(); } } while (0)
;
4398
4399 // Take this opportunity to remove dead nodes from the list
4400 int j = 0;
4401 for (int i = 0; i < _expensive_nodes.length(); i++) {
4402 Node* n = _expensive_nodes.at(i);
4403 if (!n->is_unreachable(igvn)) {
4404 assert(n->is_expensive(), "should be expensive")do { if (!(n->is_expensive())) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4404, "assert(" "n->is_expensive()" ") failed", "should be expensive"
); ::breakpoint(); } } while (0)
;
4405 _expensive_nodes.at_put(j, n);
4406 j++;
4407 }
4408 }
4409 _expensive_nodes.trunc_to(j);
4410
4411 // Then sort the list so that similar nodes are next to each other
4412 // and check for at least two nodes of identical kind with same data
4413 // inputs.
4414 sort_expensive_nodes();
4415
4416 for (int i = 0; i < _expensive_nodes.length()-1; i++) {
4417 if (cmp_expensive_nodes(_expensive_nodes.adr_at(i), _expensive_nodes.adr_at(i+1)) == 0) {
4418 return true;
4419 }
4420 }
4421
4422 return false;
4423}
4424
4425void Compile::cleanup_expensive_nodes(PhaseIterGVN &igvn) {
4426 if (_expensive_nodes.length() == 0) {
4427 return;
4428 }
4429
4430 assert(OptimizeExpensiveOps, "optimization off?")do { if (!(OptimizeExpensiveOps)) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4430, "assert(" "OptimizeExpensiveOps" ") failed", "optimization off?"
); ::breakpoint(); } } while (0)
;
4431
4432 // Sort to bring similar nodes next to each other and clear the
4433 // control input of nodes for which there's only a single copy.
4434 sort_expensive_nodes();
4435
4436 int j = 0;
4437 int identical = 0;
4438 int i = 0;
4439 bool modified = false;
4440 for (; i < _expensive_nodes.length()-1; i++) {
4441 assert(j <= i, "can't write beyond current index")do { if (!(j <= i)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4441, "assert(" "j <= i" ") failed", "can't write beyond current index"
); ::breakpoint(); } } while (0)
;
4442 if (_expensive_nodes.at(i)->Opcode() == _expensive_nodes.at(i+1)->Opcode()) {
4443 identical++;
4444 _expensive_nodes.at_put(j++, _expensive_nodes.at(i));
4445 continue;
4446 }
4447 if (identical > 0) {
4448 _expensive_nodes.at_put(j++, _expensive_nodes.at(i));
4449 identical = 0;
4450 } else {
4451 Node* n = _expensive_nodes.at(i);
4452 igvn.replace_input_of(n, 0, NULL__null);
4453 igvn.hash_insert(n);
4454 modified = true;
4455 }
4456 }
4457 if (identical > 0) {
4458 _expensive_nodes.at_put(j++, _expensive_nodes.at(i));
4459 } else if (_expensive_nodes.length() >= 1) {
4460 Node* n = _expensive_nodes.at(i);
4461 igvn.replace_input_of(n, 0, NULL__null);
4462 igvn.hash_insert(n);
4463 modified = true;
4464 }
4465 _expensive_nodes.trunc_to(j);
4466 if (modified) {
4467 igvn.optimize();
4468 }
4469}
4470
4471void Compile::add_expensive_node(Node * n) {
4472 assert(!_expensive_nodes.contains(n), "duplicate entry in expensive list")do { if (!(!_expensive_nodes.contains(n))) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4472, "assert(" "!_expensive_nodes.contains(n)" ") failed",
"duplicate entry in expensive list"); ::breakpoint(); } } while
(0)
;
4473 assert(n->is_expensive(), "expensive nodes with non-null control here only")do { if (!(n->is_expensive())) { (*g_assert_poison) = 'X';
; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4473, "assert(" "n->is_expensive()" ") failed", "expensive nodes with non-null control here only"
); ::breakpoint(); } } while (0)
;
4474 assert(!n->is_CFG() && !n->is_Mem(), "no cfg or memory nodes here")do { if (!(!n->is_CFG() && !n->is_Mem())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4474, "assert(" "!n->is_CFG() && !n->is_Mem()"
") failed", "no cfg or memory nodes here"); ::breakpoint(); }
} while (0)
;
4475 if (OptimizeExpensiveOps) {
4476 _expensive_nodes.append(n);
4477 } else {
4478 // Clear control input and let IGVN optimize expensive nodes if
4479 // OptimizeExpensiveOps is off.
4480 n->set_req(0, NULL__null);
4481 }
4482}
4483
4484/**
4485 * Track coarsened Lock and Unlock nodes.
4486 */
4487
4488class Lock_List : public Node_List {
4489 uint _origin_cnt;
4490public:
4491 Lock_List(Arena *a, uint cnt) : Node_List(a), _origin_cnt(cnt) {}
4492 uint origin_cnt() const { return _origin_cnt; }
4493};
4494
4495void Compile::add_coarsened_locks(GrowableArray<AbstractLockNode*>& locks) {
4496 int length = locks.length();
4497 if (length > 0) {
4498 // Have to keep this list until locks elimination during Macro nodes elimination.
4499 Lock_List* locks_list = new (comp_arena()) Lock_List(comp_arena(), length);
4500 for (int i = 0; i < length; i++) {
4501 AbstractLockNode* lock = locks.at(i);
4502 assert(lock->is_coarsened(), "expecting only coarsened AbstractLock nodes, but got '%s'[%d] node", lock->Name(), lock->_idx)do { if (!(lock->is_coarsened())) { (*g_assert_poison) = 'X'
;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4502, "assert(" "lock->is_coarsened()" ") failed", "expecting only coarsened AbstractLock nodes, but got '%s'[%d] node"
, lock->Name(), lock->_idx); ::breakpoint(); } } while (
0)
;
4503 locks_list->push(lock);
4504 }
4505 _coarsened_locks.append(locks_list);
4506 }
4507}
4508
4509void Compile::remove_useless_coarsened_locks(Unique_Node_List& useful) {
4510 int count = coarsened_count();
4511 for (int i = 0; i < count; i++) {
4512 Node_List* locks_list = _coarsened_locks.at(i);
4513 for (uint j = 0; j < locks_list->size(); j++) {
4514 Node* lock = locks_list->at(j);
4515 assert(lock->is_AbstractLock(), "sanity")do { if (!(lock->is_AbstractLock())) { (*g_assert_poison) =
'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4515, "assert(" "lock->is_AbstractLock()" ") failed", "sanity"
); ::breakpoint(); } } while (0)
;
4516 if (!useful.member(lock)) {
4517 locks_list->yank(lock);
4518 }
4519 }
4520 }
4521}
4522
4523void Compile::remove_coarsened_lock(Node* n) {
4524 if (n->is_AbstractLock()) {
4525 int count = coarsened_count();
4526 for (int i = 0; i < count; i++) {
4527 Node_List* locks_list = _coarsened_locks.at(i);
4528 locks_list->yank(n);
4529 }
4530 }
4531}
4532
4533bool Compile::coarsened_locks_consistent() {
4534 int count = coarsened_count();
4535 for (int i = 0; i < count; i++) {
4536 bool unbalanced = false;
4537 bool modified = false; // track locks kind modifications
4538 Lock_List* locks_list = (Lock_List*)_coarsened_locks.at(i);
4539 uint size = locks_list->size();
4540 if (size == 0) {
4541 unbalanced = false; // All locks were eliminated - good
4542 } else if (size != locks_list->origin_cnt()) {
4543 unbalanced = true; // Some locks were removed from list
4544 } else {
4545 for (uint j = 0; j < size; j++) {
4546 Node* lock = locks_list->at(j);
4547 // All nodes in group should have the same state (modified or not)
4548 if (!lock->as_AbstractLock()->is_coarsened()) {
4549 if (j == 0) {
4550 // first on list was modified, the rest should be too for consistency
4551 modified = true;
4552 } else if (!modified) {
4553 // this lock was modified but previous locks on the list were not
4554 unbalanced = true;
4555 break;
4556 }
4557 } else if (modified) {
4558 // previous locks on list were modified but not this lock
4559 unbalanced = true;
4560 break;
4561 }
4562 }
4563 }
4564 if (unbalanced) {
4565 // unbalanced monitor enter/exit - only some [un]lock nodes were removed or modified
4566#ifdef ASSERT1
4567 if (PrintEliminateLocks) {
4568 tty->print_cr("=== unbalanced coarsened locks ===");
4569 for (uint l = 0; l < size; l++) {
4570 locks_list->at(l)->dump();
4571 }
4572 }
4573#endif
4574 record_failure(C2Compiler::retry_no_locks_coarsening());
4575 return false;
4576 }
4577 }
4578 return true;
4579}
4580
4581/**
4582 * Remove the speculative part of types and clean up the graph
4583 */
4584void Compile::remove_speculative_types(PhaseIterGVN &igvn) {
4585 if (UseTypeSpeculation) {
4586 Unique_Node_List worklist;
4587 worklist.push(root());
4588 int modified = 0;
4589 // Go over all type nodes that carry a speculative type, drop the
4590 // speculative part of the type and enqueue the node for an igvn
4591 // which may optimize it out.
4592 for (uint next = 0; next < worklist.size(); ++next) {
4593 Node *n = worklist.at(next);
4594 if (n->is_Type()) {
4595 TypeNode* tn = n->as_Type();
4596 const Type* t = tn->type();
4597 const Type* t_no_spec = t->remove_speculative();
4598 if (t_no_spec != t) {
4599 bool in_hash = igvn.hash_delete(n);
4600 assert(in_hash, "node should be in igvn hash table")do { if (!(in_hash)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4600, "assert(" "in_hash" ") failed", "node should be in igvn hash table"
); ::breakpoint(); } } while (0)
;
4601 tn->set_type(t_no_spec);
4602 igvn.hash_insert(n);
4603 igvn._worklist.push(n); // give it a chance to go away
4604 modified++;
4605 }
4606 }
4607 // Iterate over outs - endless loops is unreachable from below
4608 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
4609 Node *m = n->fast_out(i);
4610 if (not_a_node(m)) {
4611 continue;
4612 }
4613 worklist.push(m);
4614 }
4615 }
4616 // Drop the speculative part of all types in the igvn's type table
4617 igvn.remove_speculative_types();
4618 if (modified > 0) {
4619 igvn.optimize();
4620 }
4621#ifdef ASSERT1
4622 // Verify that after the IGVN is over no speculative type has resurfaced
4623 worklist.clear();
4624 worklist.push(root());
4625 for (uint next = 0; next < worklist.size(); ++next) {
4626 Node *n = worklist.at(next);
4627 const Type* t = igvn.type_or_null(n);
4628 assert((t == NULL) || (t == t->remove_speculative()), "no more speculative types")do { if (!((t == __null) || (t == t->remove_speculative())
)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4628, "assert(" "(t == __null) || (t == t->remove_speculative())"
") failed", "no more speculative types"); ::breakpoint(); } }
while (0)
;
4629 if (n->is_Type()) {
4630 t = n->as_Type()->type();
4631 assert(t == t->remove_speculative(), "no more speculative types")do { if (!(t == t->remove_speculative())) { (*g_assert_poison
) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4631, "assert(" "t == t->remove_speculative()" ") failed"
, "no more speculative types"); ::breakpoint(); } } while (0)
;
4632 }
4633 // Iterate over outs - endless loops is unreachable from below
4634 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
4635 Node *m = n->fast_out(i);
4636 if (not_a_node(m)) {
4637 continue;
4638 }
4639 worklist.push(m);
4640 }
4641 }
4642 igvn.check_no_speculative_types();
4643#endif
4644 }
4645}
4646
4647// Auxiliary methods to support randomized stressing/fuzzing.
4648
4649int Compile::random() {
4650 _stress_seed = os::next_random(_stress_seed);
4651 return static_cast<int>(_stress_seed);
4652}
4653
4654// This method can be called the arbitrary number of times, with current count
4655// as the argument. The logic allows selecting a single candidate from the
4656// running list of candidates as follows:
4657// int count = 0;
4658// Cand* selected = null;
4659// while(cand = cand->next()) {
4660// if (randomized_select(++count)) {
4661// selected = cand;
4662// }
4663// }
4664//
4665// Including count equalizes the chances any candidate is "selected".
4666// This is useful when we don't have the complete list of candidates to choose
4667// from uniformly. In this case, we need to adjust the randomicity of the
4668// selection, or else we will end up biasing the selection towards the latter
4669// candidates.
4670//
4671// Quick back-envelope calculation shows that for the list of n candidates
4672// the equal probability for the candidate to persist as "best" can be
4673// achieved by replacing it with "next" k-th candidate with the probability
4674// of 1/k. It can be easily shown that by the end of the run, the
4675// probability for any candidate is converged to 1/n, thus giving the
4676// uniform distribution among all the candidates.
4677//
4678// We don't care about the domain size as long as (RANDOMIZED_DOMAIN / count) is large.
4679#define RANDOMIZED_DOMAIN_POW29 29
4680#define RANDOMIZED_DOMAIN(1 << 29) (1 << RANDOMIZED_DOMAIN_POW29)
4681#define RANDOMIZED_DOMAIN_MASK((1 << (29 + 1)) - 1) ((1 << (RANDOMIZED_DOMAIN_POW29 + 1)) - 1)
4682bool Compile::randomized_select(int count) {
4683 assert(count > 0, "only positive")do { if (!(count > 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4683, "assert(" "count > 0" ") failed", "only positive")
; ::breakpoint(); } } while (0)
;
4684 return (random() & RANDOMIZED_DOMAIN_MASK((1 << (29 + 1)) - 1)) < (RANDOMIZED_DOMAIN(1 << 29) / count);
4685}
4686
4687CloneMap& Compile::clone_map() { return _clone_map; }
4688void Compile::set_clone_map(Dict* d) { _clone_map._dict = d; }
4689
4690void NodeCloneInfo::dump() const {
4691 tty->print(" {%d:%d} ", idx(), gen());
4692}
4693
4694void CloneMap::clone(Node* old, Node* nnn, int gen) {
4695 uint64_t val = value(old->_idx);
4696 NodeCloneInfo cio(val);
4697 assert(val != 0, "old node should be in the map")do { if (!(val != 0)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4697, "assert(" "val != 0" ") failed", "old node should be in the map"
); ::breakpoint(); } } while (0)
;
4698 NodeCloneInfo cin(cio.idx(), gen + cio.gen());
4699 insert(nnn->_idx, cin.get());
4700#ifndef PRODUCT
4701 if (is_debug()) {
4702 tty->print_cr("CloneMap::clone inserted node %d info {%d:%d} into CloneMap", nnn->_idx, cin.idx(), cin.gen());
4703 }
4704#endif
4705}
4706
4707void CloneMap::verify_insert_and_clone(Node* old, Node* nnn, int gen) {
4708 NodeCloneInfo cio(value(old->_idx));
4709 if (cio.get() == 0) {
4710 cio.set(old->_idx, 0);
4711 insert(old->_idx, cio.get());
4712#ifndef PRODUCT
4713 if (is_debug()) {
4714 tty->print_cr("CloneMap::verify_insert_and_clone inserted node %d info {%d:%d} into CloneMap", old->_idx, cio.idx(), cio.gen());
4715 }
4716#endif
4717 }
4718 clone(old, nnn, gen);
4719}
4720
4721int CloneMap::max_gen() const {
4722 int g = 0;
4723 DictI di(_dict);
4724 for(; di.test(); ++di) {
4725 int t = gen(di._key);
4726 if (g < t) {
4727 g = t;
4728#ifndef PRODUCT
4729 if (is_debug()) {
4730 tty->print_cr("CloneMap::max_gen() update max=%d from %d", g, _2_node_idx_t(di._key));
4731 }
4732#endif
4733 }
4734 }
4735 return g;
4736}
4737
4738void CloneMap::dump(node_idx_t key) const {
4739 uint64_t val = value(key);
4740 if (val != 0) {
4741 NodeCloneInfo ni(val);
4742 ni.dump();
4743 }
4744}
4745
4746// Move Allocate nodes to the start of the list
4747void Compile::sort_macro_nodes() {
4748 int count = macro_count();
4749 int allocates = 0;
4750 for (int i = 0; i < count; i++) {
4751 Node* n = macro_node(i);
4752 if (n->is_Allocate()) {
4753 if (i != allocates) {
4754 Node* tmp = macro_node(allocates);
4755 _macro_nodes.at_put(allocates, n);
4756 _macro_nodes.at_put(i, tmp);
4757 }
4758 allocates++;
4759 }
4760 }
4761}
4762
4763void Compile::print_method(CompilerPhaseType cpt, const char *name, int level) {
4764 EventCompilerPhase event;
4765 if (event.should_commit()) {
4766 CompilerEvent::PhaseEvent::post(event, C->_latest_stage_start_counter, cpt, C->_compile_id, level);
4767 }
4768#ifndef PRODUCT
4769 if (should_print(level)) {
4770 _printer->print_method(name, level);
4771 }
4772#endif
4773 C->_latest_stage_start_counter.stamp();
4774}
4775
4776void Compile::print_method(CompilerPhaseType cpt, int level, int idx) {
4777 char output[1024];
4778#ifndef PRODUCT
4779 if (idx != 0) {
4780 jio_snprintf(output, sizeof(output), "%s:%d", CompilerPhaseTypeHelper::to_string(cpt), idx);
4781 } else {
4782 jio_snprintf(output, sizeof(output), "%s", CompilerPhaseTypeHelper::to_string(cpt));
4783 }
4784#endif
4785 print_method(cpt, output, level);
4786}
4787
4788void Compile::print_method(CompilerPhaseType cpt, Node* n, int level) {
4789 ResourceMark rm;
4790 stringStream ss;
4791 ss.print_raw(CompilerPhaseTypeHelper::to_string(cpt));
4792 if (n != NULL__null) {
4793 ss.print(": %d %s ", n->_idx, NodeClassNames[n->Opcode()]);
4794 } else {
4795 ss.print_raw(": NULL");
4796 }
4797 C->print_method(cpt, ss.as_string(), level);
4798}
4799
4800void Compile::end_method(int level) {
4801 EventCompilerPhase event;
4802 if (event.should_commit()) {
4803 CompilerEvent::PhaseEvent::post(event, C->_latest_stage_start_counter, PHASE_END, C->_compile_id, level);
4804 }
4805
4806#ifndef PRODUCT
4807 if (_method != NULL__null && should_print(level)) {
4808 _printer->end_method();
4809 }
4810#endif
4811}
4812
4813
4814#ifndef PRODUCT
4815IdealGraphPrinter* Compile::_debug_file_printer = NULL__null;
4816IdealGraphPrinter* Compile::_debug_network_printer = NULL__null;
4817
4818// Called from debugger. Prints method to the default file with the default phase name.
4819// This works regardless of any Ideal Graph Visualizer flags set or not.
4820void igv_print() {
4821 Compile::current()->igv_print_method_to_file();
4822}
4823
4824// Same as igv_print() above but with a specified phase name.
4825void igv_print(const char* phase_name) {
4826 Compile::current()->igv_print_method_to_file(phase_name);
4827}
4828
4829// Called from debugger. Prints method with the default phase name to the default network or the one specified with
4830// the network flags for the Ideal Graph Visualizer, or to the default file depending on the 'network' argument.
4831// This works regardless of any Ideal Graph Visualizer flags set or not.
4832void igv_print(bool network) {
4833 if (network) {
4834 Compile::current()->igv_print_method_to_network();
4835 } else {
4836 Compile::current()->igv_print_method_to_file();
4837 }
4838}
4839
4840// Same as igv_print(bool network) above but with a specified phase name.
4841void igv_print(bool network, const char* phase_name) {
4842 if (network) {
4843 Compile::current()->igv_print_method_to_network(phase_name);
4844 } else {
4845 Compile::current()->igv_print_method_to_file(phase_name);
4846 }
4847}
4848
4849// Called from debugger. Normal write to the default _printer. Only works if Ideal Graph Visualizer printing flags are set.
4850void igv_print_default() {
4851 Compile::current()->print_method(PHASE_DEBUG, 0);
4852}
4853
4854// Called from debugger, especially when replaying a trace in which the program state cannot be altered like with rr replay.
4855// A method is appended to an existing default file with the default phase name. This means that igv_append() must follow
4856// an earlier igv_print(*) call which sets up the file. This works regardless of any Ideal Graph Visualizer flags set or not.
4857void igv_append() {
4858 Compile::current()->igv_print_method_to_file("Debug", true);
4859}
4860
4861// Same as igv_append() above but with a specified phase name.
4862void igv_append(const char* phase_name) {
4863 Compile::current()->igv_print_method_to_file(phase_name, true);
4864}
4865
4866void Compile::igv_print_method_to_file(const char* phase_name, bool append) {
4867 const char* file_name = "custom_debug.xml";
4868 if (_debug_file_printer == NULL__null) {
4869 _debug_file_printer = new IdealGraphPrinter(C, file_name, append);
4870 } else {
4871 _debug_file_printer->update_compiled_method(C->method());
4872 }
4873 tty->print_cr("Method %s to %s", append ? "appended" : "printed", file_name);
4874 _debug_file_printer->print(phase_name, (Node*)C->root());
4875}
4876
4877void Compile::igv_print_method_to_network(const char* phase_name) {
4878 if (_debug_network_printer == NULL__null) {
4879 _debug_network_printer = new IdealGraphPrinter(C);
4880 } else {
4881 _debug_network_printer->update_compiled_method(C->method());
4882 }
4883 tty->print_cr("Method printed over network stream to IGV");
4884 _debug_network_printer->print(phase_name, (Node*)C->root());
4885}
4886#endif
4887
4888void Compile::add_native_invoker(RuntimeStub* stub) {
4889 _native_invokers.append(stub);
4890}
4891
4892Node* Compile::narrow_value(BasicType bt, Node* value, const Type* type, PhaseGVN* phase, bool transform_res) {
4893 if (type != NULL__null && phase->type(value)->higher_equal(type)) {
4894 return value;
4895 }
4896 Node* result = NULL__null;
4897 if (bt == T_BYTE) {
4898 result = phase->transform(new LShiftINode(value, phase->intcon(24)));
4899 result = new RShiftINode(result, phase->intcon(24));
4900 } else if (bt == T_BOOLEAN) {
4901 result = new AndINode(value, phase->intcon(0xFF));
4902 } else if (bt == T_CHAR) {
4903 result = new AndINode(value,phase->intcon(0xFFFF));
4904 } else {
4905 assert(bt == T_SHORT, "unexpected narrow type")do { if (!(bt == T_SHORT)) { (*g_assert_poison) = 'X';; report_vm_error
("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/compile.cpp"
, 4905, "assert(" "bt == T_SHORT" ") failed", "unexpected narrow type"
); ::breakpoint(); } } while (0)
;
4906 result = phase->transform(new LShiftINode(value, phase->intcon(16)));
4907 result = new RShiftINode(result, phase->intcon(16));
4908 }
4909 if (transform_res) {
4910 result = phase->transform(result);
4911 }
4912 return result;
4913}
4914