src/share/vm/opto/graphKit.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_OPTO_GRAPHKIT_HPP
aoqi@0 26 #define SHARE_VM_OPTO_GRAPHKIT_HPP
aoqi@0 27
aoqi@0 28 #include "ci/ciEnv.hpp"
aoqi@0 29 #include "ci/ciMethodData.hpp"
aoqi@0 30 #include "opto/addnode.hpp"
aoqi@0 31 #include "opto/callnode.hpp"
aoqi@0 32 #include "opto/cfgnode.hpp"
aoqi@0 33 #include "opto/compile.hpp"
aoqi@0 34 #include "opto/divnode.hpp"
aoqi@0 35 #include "opto/mulnode.hpp"
aoqi@0 36 #include "opto/phaseX.hpp"
aoqi@0 37 #include "opto/subnode.hpp"
aoqi@0 38 #include "opto/type.hpp"
aoqi@0 39 #include "runtime/deoptimization.hpp"
aoqi@0 40
aoqi@0 41 class FastLockNode;
aoqi@0 42 class FastUnlockNode;
aoqi@0 43 class IdealKit;
aoqi@0 44 class LibraryCallKit;
aoqi@0 45 class Parse;
aoqi@0 46 class RootNode;
aoqi@0 47
aoqi@0 48 //-----------------------------------------------------------------------------
aoqi@0 49 //----------------------------GraphKit-----------------------------------------
aoqi@0 50 // Toolkit for building the common sorts of subgraphs.
aoqi@0 51 // Does not know about bytecode parsing or type-flow results.
aoqi@0 52 // It is able to create graphs implementing the semantics of most
aoqi@0 53 // or all bytecodes, so that it can expand intrinsics and calls.
aoqi@0 54 // It may depend on JVMState structure, but it must not depend
aoqi@0 55 // on specific bytecode streams.
aoqi@0 56 class GraphKit : public Phase {
aoqi@0 57 friend class PreserveJVMState;
aoqi@0 58
aoqi@0 59 protected:
aoqi@0 60 ciEnv* _env; // Compilation environment
aoqi@0 61 PhaseGVN &_gvn; // Some optimizations while parsing
aoqi@0 62 SafePointNode* _map; // Parser map from JVM to Nodes
aoqi@0 63 SafePointNode* _exceptions;// Parser map(s) for exception state(s)
aoqi@0 64 int _bci; // JVM Bytecode Pointer
aoqi@0 65 ciMethod* _method; // JVM Current Method
aoqi@0 66
aoqi@0 67 private:
aoqi@0 68 int _sp; // JVM Expression Stack Pointer; don't modify directly!
aoqi@0 69
aoqi@0 70 private:
aoqi@0 71 SafePointNode* map_not_null() const {
aoqi@0 72 assert(_map != NULL, "must call stopped() to test for reset compiler map");
aoqi@0 73 return _map;
aoqi@0 74 }
aoqi@0 75
aoqi@0 76 public:
aoqi@0 77 GraphKit(); // empty constructor
aoqi@0 78 GraphKit(JVMState* jvms); // the JVM state on which to operate
aoqi@0 79
aoqi@0 80 #ifdef ASSERT
aoqi@0 81 ~GraphKit() {
aoqi@0 82 assert(!has_exceptions(), "user must call transfer_exceptions_into_jvms");
aoqi@0 83 }
aoqi@0 84 #endif
aoqi@0 85
aoqi@0 86 virtual Parse* is_Parse() const { return NULL; }
aoqi@0 87 virtual LibraryCallKit* is_LibraryCallKit() const { return NULL; }
aoqi@0 88
aoqi@0 89 ciEnv* env() const { return _env; }
aoqi@0 90 PhaseGVN& gvn() const { return _gvn; }
aoqi@0 91
aoqi@0 92 void record_for_igvn(Node* n) const { C->record_for_igvn(n); } // delegate to Compile
aoqi@0 93
aoqi@0 94 // Handy well-known nodes:
aoqi@0 95 Node* null() const { return zerocon(T_OBJECT); }
aoqi@0 96 Node* top() const { return C->top(); }
aoqi@0 97 RootNode* root() const { return C->root(); }
aoqi@0 98
aoqi@0 99 // Create or find a constant node
aoqi@0 100 Node* intcon(jint con) const { return _gvn.intcon(con); }
aoqi@0 101 Node* longcon(jlong con) const { return _gvn.longcon(con); }
aoqi@0 102 Node* makecon(const Type *t) const { return _gvn.makecon(t); }
aoqi@0 103 Node* zerocon(BasicType bt) const { return _gvn.zerocon(bt); }
aoqi@0 104 // (See also macro MakeConX in type.hpp, which uses intcon or longcon.)
aoqi@0 105
aoqi@0 106 // Helper for byte_map_base
aoqi@0 107 Node* byte_map_base_node() {
aoqi@0 108 // Get base of card map
aoqi@0 109 CardTableModRefBS* ct = (CardTableModRefBS*)(Universe::heap()->barrier_set());
aoqi@0 110 assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust users of this code");
aoqi@0 111 if (ct->byte_map_base != NULL) {
aoqi@0 112 return makecon(TypeRawPtr::make((address)ct->byte_map_base));
aoqi@0 113 } else {
aoqi@0 114 return null();
aoqi@0 115 }
aoqi@0 116 }
aoqi@0 117
aoqi@0 118 jint find_int_con(Node* n, jint value_if_unknown) {
aoqi@0 119 return _gvn.find_int_con(n, value_if_unknown);
aoqi@0 120 }
aoqi@0 121 jlong find_long_con(Node* n, jlong value_if_unknown) {
aoqi@0 122 return _gvn.find_long_con(n, value_if_unknown);
aoqi@0 123 }
aoqi@0 124 // (See also macro find_intptr_t_con in type.hpp, which uses one of these.)
aoqi@0 125
aoqi@0 126 // JVM State accessors:
aoqi@0 127 // Parser mapping from JVM indices into Nodes.
aoqi@0 128 // Low slots are accessed by the StartNode::enum.
aoqi@0 129 // Then come the locals at StartNode::Parms to StartNode::Parms+max_locals();
aoqi@0 130 // Then come JVM stack slots.
aoqi@0 131 // Finally come the monitors, if any.
aoqi@0 132 // See layout accessors in class JVMState.
aoqi@0 133
aoqi@0 134 SafePointNode* map() const { return _map; }
aoqi@0 135 bool has_exceptions() const { return _exceptions != NULL; }
aoqi@0 136 JVMState* jvms() const { return map_not_null()->_jvms; }
aoqi@0 137 int sp() const { return _sp; }
aoqi@0 138 int bci() const { return _bci; }
aoqi@0 139 Bytecodes::Code java_bc() const;
aoqi@0 140 ciMethod* method() const { return _method; }
aoqi@0 141
aoqi@0 142 void set_jvms(JVMState* jvms) { set_map(jvms->map());
aoqi@0 143 assert(jvms == this->jvms(), "sanity");
aoqi@0 144 _sp = jvms->sp();
aoqi@0 145 _bci = jvms->bci();
aoqi@0 146 _method = jvms->has_method() ? jvms->method() : NULL; }
aoqi@0 147 void set_map(SafePointNode* m) { _map = m; debug_only(verify_map()); }
aoqi@0 148 void set_sp(int sp) { assert(sp >= 0, err_msg_res("sp must be non-negative: %d", sp)); _sp = sp; }
aoqi@0 149 void clean_stack(int from_sp); // clear garbage beyond from_sp to top
aoqi@0 150
aoqi@0 151 void inc_sp(int i) { set_sp(sp() + i); }
aoqi@0 152 void dec_sp(int i) { set_sp(sp() - i); }
aoqi@0 153 void set_bci(int bci) { _bci = bci; }
aoqi@0 154
aoqi@0 155 // Make sure jvms has current bci & sp.
aoqi@0 156 JVMState* sync_jvms() const;
aoqi@0 157 JVMState* sync_jvms_for_reexecute();
aoqi@0 158
aoqi@0 159 #ifdef ASSERT
aoqi@0 160 // Make sure JVMS has an updated copy of bci and sp.
aoqi@0 161 // Also sanity-check method, depth, and monitor depth.
aoqi@0 162 bool jvms_in_sync() const;
aoqi@0 163
aoqi@0 164 // Make sure the map looks OK.
aoqi@0 165 void verify_map() const;
aoqi@0 166
aoqi@0 167 // Make sure a proposed exception state looks OK.
aoqi@0 168 static void verify_exception_state(SafePointNode* ex_map);
aoqi@0 169 #endif
aoqi@0 170
aoqi@0 171 // Clone the existing map state. (Implements PreserveJVMState.)
aoqi@0 172 SafePointNode* clone_map();
aoqi@0 173
aoqi@0 174 // Set the map to a clone of the given one.
aoqi@0 175 void set_map_clone(SafePointNode* m);
aoqi@0 176
aoqi@0 177 // Tell if the compilation is failing.
aoqi@0 178 bool failing() const { return C->failing(); }
aoqi@0 179
aoqi@0 180 // Set _map to NULL, signalling a stop to further bytecode execution.
aoqi@0 181 // Preserve the map intact for future use, and return it back to the caller.
aoqi@0 182 SafePointNode* stop() { SafePointNode* m = map(); set_map(NULL); return m; }
aoqi@0 183
aoqi@0 184 // Stop, but first smash the map's inputs to NULL, to mark it dead.
aoqi@0 185 void stop_and_kill_map();
aoqi@0 186
aoqi@0 187 // Tell if _map is NULL, or control is top.
aoqi@0 188 bool stopped();
aoqi@0 189
aoqi@0 190 // Tell if this method or any caller method has exception handlers.
aoqi@0 191 bool has_ex_handler();
aoqi@0 192
aoqi@0 193 // Save an exception without blowing stack contents or other JVM state.
aoqi@0 194 // (The extra pointer is stuck with add_req on the map, beyond the JVMS.)
aoqi@0 195 static void set_saved_ex_oop(SafePointNode* ex_map, Node* ex_oop);
aoqi@0 196
aoqi@0 197 // Recover a saved exception from its map.
aoqi@0 198 static Node* saved_ex_oop(SafePointNode* ex_map);
aoqi@0 199
aoqi@0 200 // Recover a saved exception from its map, and remove it from the map.
aoqi@0 201 static Node* clear_saved_ex_oop(SafePointNode* ex_map);
aoqi@0 202
aoqi@0 203 #ifdef ASSERT
aoqi@0 204 // Recover a saved exception from its map, and remove it from the map.
aoqi@0 205 static bool has_saved_ex_oop(SafePointNode* ex_map);
aoqi@0 206 #endif
aoqi@0 207
aoqi@0 208 // Push an exception in the canonical position for handlers (stack(0)).
aoqi@0 209 void push_ex_oop(Node* ex_oop) {
aoqi@0 210 ensure_stack(1); // ensure room to push the exception
aoqi@0 211 set_stack(0, ex_oop);
aoqi@0 212 set_sp(1);
aoqi@0 213 clean_stack(1);
aoqi@0 214 }
aoqi@0 215
aoqi@0 216 // Detach and return an exception state.
aoqi@0 217 SafePointNode* pop_exception_state() {
aoqi@0 218 SafePointNode* ex_map = _exceptions;
aoqi@0 219 if (ex_map != NULL) {
aoqi@0 220 _exceptions = ex_map->next_exception();
aoqi@0 221 ex_map->set_next_exception(NULL);
aoqi@0 222 debug_only(verify_exception_state(ex_map));
aoqi@0 223 }
aoqi@0 224 return ex_map;
aoqi@0 225 }
aoqi@0 226
aoqi@0 227 // Add an exception, using the given JVM state, without commoning.
aoqi@0 228 void push_exception_state(SafePointNode* ex_map) {
aoqi@0 229 debug_only(verify_exception_state(ex_map));
aoqi@0 230 ex_map->set_next_exception(_exceptions);
aoqi@0 231 _exceptions = ex_map;
aoqi@0 232 }
aoqi@0 233
aoqi@0 234 // Turn the current JVM state into an exception state, appending the ex_oop.
aoqi@0 235 SafePointNode* make_exception_state(Node* ex_oop);
aoqi@0 236
aoqi@0 237 // Add an exception, using the given JVM state.
aoqi@0 238 // Combine all exceptions with a common exception type into a single state.
aoqi@0 239 // (This is done via combine_exception_states.)
aoqi@0 240 void add_exception_state(SafePointNode* ex_map);
aoqi@0 241
aoqi@0 242 // Combine all exceptions of any sort whatever into a single master state.
aoqi@0 243 SafePointNode* combine_and_pop_all_exception_states() {
aoqi@0 244 if (_exceptions == NULL) return NULL;
aoqi@0 245 SafePointNode* phi_map = pop_exception_state();
aoqi@0 246 SafePointNode* ex_map;
aoqi@0 247 while ((ex_map = pop_exception_state()) != NULL) {
aoqi@0 248 combine_exception_states(ex_map, phi_map);
aoqi@0 249 }
aoqi@0 250 return phi_map;
aoqi@0 251 }
aoqi@0 252
aoqi@0 253 // Combine the two exception states, building phis as necessary.
aoqi@0 254 // The second argument is updated to include contributions from the first.
aoqi@0 255 void combine_exception_states(SafePointNode* ex_map, SafePointNode* phi_map);
aoqi@0 256
aoqi@0 257 // Reset the map to the given state. If there are any half-finished phis
aoqi@0 258 // in it (created by combine_exception_states), transform them now.
aoqi@0 259 // Returns the exception oop. (Caller must call push_ex_oop if required.)
aoqi@0 260 Node* use_exception_state(SafePointNode* ex_map);
aoqi@0 261
aoqi@0 262 // Collect exceptions from a given JVM state into my exception list.
aoqi@0 263 void add_exception_states_from(JVMState* jvms);
aoqi@0 264
aoqi@0 265 // Collect all raised exceptions into the current JVM state.
aoqi@0 266 // Clear the current exception list and map, returns the combined states.
aoqi@0 267 JVMState* transfer_exceptions_into_jvms();
aoqi@0 268
aoqi@0 269 // Helper to throw a built-in exception.
aoqi@0 270 // Range checks take the offending index.
aoqi@0 271 // Cast and array store checks take the offending class.
aoqi@0 272 // Others do not take the optional argument.
aoqi@0 273 // The JVMS must allow the bytecode to be re-executed
aoqi@0 274 // via an uncommon trap.
aoqi@0 275 void builtin_throw(Deoptimization::DeoptReason reason, Node* arg = NULL);
aoqi@0 276
aoqi@0 277 // Helper to check the JavaThread::_should_post_on_exceptions flag
aoqi@0 278 // and branch to an uncommon_trap if it is true (with the specified reason and must_throw)
aoqi@0 279 void uncommon_trap_if_should_post_on_exceptions(Deoptimization::DeoptReason reason,
aoqi@0 280 bool must_throw) ;
aoqi@0 281
aoqi@0 282 // Helper Functions for adding debug information
aoqi@0 283 void kill_dead_locals();
aoqi@0 284 #ifdef ASSERT
aoqi@0 285 bool dead_locals_are_killed();
aoqi@0 286 #endif
aoqi@0 287 // The call may deoptimize. Supply required JVM state as debug info.
aoqi@0 288 // If must_throw is true, the call is guaranteed not to return normally.
aoqi@0 289 void add_safepoint_edges(SafePointNode* call,
aoqi@0 290 bool must_throw = false);
aoqi@0 291
aoqi@0 292 // How many stack inputs does the current BC consume?
aoqi@0 293 // And, how does the stack change after the bytecode?
aoqi@0 294 // Returns false if unknown.
aoqi@0 295 bool compute_stack_effects(int& inputs, int& depth);
aoqi@0 296
aoqi@0 297 // Add a fixed offset to a pointer
aoqi@0 298 Node* basic_plus_adr(Node* base, Node* ptr, intptr_t offset) {
aoqi@0 299 return basic_plus_adr(base, ptr, MakeConX(offset));
aoqi@0 300 }
aoqi@0 301 Node* basic_plus_adr(Node* base, intptr_t offset) {
aoqi@0 302 return basic_plus_adr(base, base, MakeConX(offset));
aoqi@0 303 }
aoqi@0 304 // Add a variable offset to a pointer
aoqi@0 305 Node* basic_plus_adr(Node* base, Node* offset) {
aoqi@0 306 return basic_plus_adr(base, base, offset);
aoqi@0 307 }
aoqi@0 308 Node* basic_plus_adr(Node* base, Node* ptr, Node* offset);
aoqi@0 309
aoqi@0 310
aoqi@0 311 // Some convenient shortcuts for common nodes
aoqi@0 312 Node* IfTrue(IfNode* iff) { return _gvn.transform(new (C) IfTrueNode(iff)); }
aoqi@0 313 Node* IfFalse(IfNode* iff) { return _gvn.transform(new (C) IfFalseNode(iff)); }
aoqi@0 314
aoqi@0 315 Node* AddI(Node* l, Node* r) { return _gvn.transform(new (C) AddINode(l, r)); }
aoqi@0 316 Node* SubI(Node* l, Node* r) { return _gvn.transform(new (C) SubINode(l, r)); }
aoqi@0 317 Node* MulI(Node* l, Node* r) { return _gvn.transform(new (C) MulINode(l, r)); }
aoqi@0 318 Node* DivI(Node* ctl, Node* l, Node* r) { return _gvn.transform(new (C) DivINode(ctl, l, r)); }
aoqi@0 319
aoqi@0 320 Node* AndI(Node* l, Node* r) { return _gvn.transform(new (C) AndINode(l, r)); }
aoqi@0 321 Node* OrI(Node* l, Node* r) { return _gvn.transform(new (C) OrINode(l, r)); }
aoqi@0 322 Node* XorI(Node* l, Node* r) { return _gvn.transform(new (C) XorINode(l, r)); }
aoqi@0 323
aoqi@0 324 Node* MaxI(Node* l, Node* r) { return _gvn.transform(new (C) MaxINode(l, r)); }
aoqi@0 325 Node* MinI(Node* l, Node* r) { return _gvn.transform(new (C) MinINode(l, r)); }
aoqi@0 326
aoqi@0 327 Node* LShiftI(Node* l, Node* r) { return _gvn.transform(new (C) LShiftINode(l, r)); }
aoqi@0 328 Node* RShiftI(Node* l, Node* r) { return _gvn.transform(new (C) RShiftINode(l, r)); }
aoqi@0 329 Node* URShiftI(Node* l, Node* r) { return _gvn.transform(new (C) URShiftINode(l, r)); }
aoqi@0 330
aoqi@0 331 Node* CmpI(Node* l, Node* r) { return _gvn.transform(new (C) CmpINode(l, r)); }
aoqi@0 332 Node* CmpL(Node* l, Node* r) { return _gvn.transform(new (C) CmpLNode(l, r)); }
aoqi@0 333 Node* CmpP(Node* l, Node* r) { return _gvn.transform(new (C) CmpPNode(l, r)); }
aoqi@0 334 Node* Bool(Node* cmp, BoolTest::mask relop) { return _gvn.transform(new (C) BoolNode(cmp, relop)); }
aoqi@0 335
aoqi@0 336 Node* AddP(Node* b, Node* a, Node* o) { return _gvn.transform(new (C) AddPNode(b, a, o)); }
aoqi@0 337
aoqi@0 338 // Convert between int and long, and size_t.
aoqi@0 339 // (See macros ConvI2X, etc., in type.hpp for ConvI2X, etc.)
aoqi@0 340 Node* ConvI2L(Node* offset);
aoqi@0 341 Node* ConvI2UL(Node* offset);
aoqi@0 342 Node* ConvL2I(Node* offset);
aoqi@0 343 // Find out the klass of an object.
aoqi@0 344 Node* load_object_klass(Node* object);
aoqi@0 345 // Find out the length of an array.
aoqi@0 346 Node* load_array_length(Node* array);
aoqi@0 347
aoqi@0 348
aoqi@0 349 // Helper function to do a NULL pointer check or ZERO check based on type.
aoqi@0 350 // Throw an exception if a given value is null.
aoqi@0 351 // Return the value cast to not-null.
aoqi@0 352 // Be clever about equivalent dominating null checks.
aoqi@0 353 Node* null_check_common(Node* value, BasicType type,
aoqi@0 354 bool assert_null = false, Node* *null_control = NULL);
aoqi@0 355 Node* null_check(Node* value, BasicType type = T_OBJECT) {
aoqi@0 356 return null_check_common(value, type);
aoqi@0 357 }
aoqi@0 358 Node* null_check_receiver() {
aoqi@0 359 assert(argument(0)->bottom_type()->isa_ptr(), "must be");
aoqi@0 360 return null_check(argument(0));
aoqi@0 361 }
aoqi@0 362 Node* zero_check_int(Node* value) {
aoqi@0 363 assert(value->bottom_type()->basic_type() == T_INT,
aoqi@0 364 err_msg_res("wrong type: %s", type2name(value->bottom_type()->basic_type())));
aoqi@0 365 return null_check_common(value, T_INT);
aoqi@0 366 }
aoqi@0 367 Node* zero_check_long(Node* value) {
aoqi@0 368 assert(value->bottom_type()->basic_type() == T_LONG,
aoqi@0 369 err_msg_res("wrong type: %s", type2name(value->bottom_type()->basic_type())));
aoqi@0 370 return null_check_common(value, T_LONG);
aoqi@0 371 }
aoqi@0 372 // Throw an uncommon trap if a given value is __not__ null.
aoqi@0 373 // Return the value cast to null, and be clever about dominating checks.
aoqi@0 374 Node* null_assert(Node* value, BasicType type = T_OBJECT) {
aoqi@0 375 return null_check_common(value, type, true);
aoqi@0 376 }
aoqi@0 377
aoqi@0 378 // Null check oop. Return null-path control into (*null_control).
aoqi@0 379 // Return a cast-not-null node which depends on the not-null control.
aoqi@0 380 // If never_see_null, use an uncommon trap (*null_control sees a top).
aoqi@0 381 // The cast is not valid along the null path; keep a copy of the original.
aoqi@0 382 // If safe_for_replace, then we can replace the value with the cast
aoqi@0 383 // in the parsing map (the cast is guaranteed to dominate the map)
aoqi@0 384 Node* null_check_oop(Node* value, Node* *null_control,
aoqi@0 385 bool never_see_null = false, bool safe_for_replace = false);
aoqi@0 386
aoqi@0 387 // Check the null_seen bit.
aoqi@0 388 bool seems_never_null(Node* obj, ciProfileData* data);
aoqi@0 389
aoqi@0 390 // Check for unique class for receiver at call
aoqi@0 391 ciKlass* profile_has_unique_klass() {
aoqi@0 392 ciCallProfile profile = method()->call_profile_at_bci(bci());
aoqi@0 393 if (profile.count() >= 0 && // no cast failures here
aoqi@0 394 profile.has_receiver(0) &&
aoqi@0 395 profile.morphism() == 1) {
aoqi@0 396 return profile.receiver(0);
aoqi@0 397 }
aoqi@0 398 return NULL;
aoqi@0 399 }
aoqi@0 400
aoqi@0 401 // record type from profiling with the type system
aoqi@0 402 Node* record_profile_for_speculation(Node* n, ciKlass* exact_kls);
aoqi@0 403 Node* record_profiled_receiver_for_speculation(Node* n);
aoqi@0 404 void record_profiled_arguments_for_speculation(ciMethod* dest_method, Bytecodes::Code bc);
aoqi@0 405 void record_profiled_parameters_for_speculation();
aoqi@0 406
aoqi@0 407 // Use the type profile to narrow an object type.
aoqi@0 408 Node* maybe_cast_profiled_receiver(Node* not_null_obj,
aoqi@0 409 ciKlass* require_klass,
aoqi@0 410 ciKlass* spec,
aoqi@0 411 bool safe_for_replace);
aoqi@0 412
aoqi@0 413 // Cast obj to type and emit guard unless we had too many traps here already
aoqi@0 414 Node* maybe_cast_profiled_obj(Node* obj,
aoqi@0 415 ciKlass* type,
aoqi@0 416 bool not_null = false);
aoqi@0 417
aoqi@0 418 // Cast obj to not-null on this path
aoqi@0 419 Node* cast_not_null(Node* obj, bool do_replace_in_map = true);
aoqi@0 420 // Replace all occurrences of one node by another.
aoqi@0 421 void replace_in_map(Node* old, Node* neww);
aoqi@0 422
aoqi@0 423 void push(Node* n) { map_not_null(); _map->set_stack(_map->_jvms, _sp++ , n); }
aoqi@0 424 Node* pop() { map_not_null(); return _map->stack( _map->_jvms, --_sp ); }
aoqi@0 425 Node* peek(int off = 0) { map_not_null(); return _map->stack( _map->_jvms, _sp - off - 1 ); }
aoqi@0 426
aoqi@0 427 void push_pair(Node* ldval) {
aoqi@0 428 push(ldval);
aoqi@0 429 push(top()); // the halfword is merely a placeholder
aoqi@0 430 }
aoqi@0 431 void push_pair_local(int i) {
aoqi@0 432 // longs are stored in locals in "push" order
aoqi@0 433 push( local(i+0) ); // the real value
aoqi@0 434 assert(local(i+1) == top(), "");
aoqi@0 435 push(top()); // halfword placeholder
aoqi@0 436 }
aoqi@0 437 Node* pop_pair() {
aoqi@0 438 // the second half is pushed last & popped first; it contains exactly nothing
aoqi@0 439 Node* halfword = pop();
aoqi@0 440 assert(halfword == top(), "");
aoqi@0 441 // the long bits are pushed first & popped last:
aoqi@0 442 return pop();
aoqi@0 443 }
aoqi@0 444 void set_pair_local(int i, Node* lval) {
aoqi@0 445 // longs are stored in locals as a value/half pair (like doubles)
aoqi@0 446 set_local(i+0, lval);
aoqi@0 447 set_local(i+1, top());
aoqi@0 448 }
aoqi@0 449
aoqi@0 450 // Push the node, which may be zero, one, or two words.
aoqi@0 451 void push_node(BasicType n_type, Node* n) {
aoqi@0 452 int n_size = type2size[n_type];
aoqi@0 453 if (n_size == 1) push( n ); // T_INT, ...
aoqi@0 454 else if (n_size == 2) push_pair( n ); // T_DOUBLE, T_LONG
aoqi@0 455 else { assert(n_size == 0, "must be T_VOID"); }
aoqi@0 456 }
aoqi@0 457
aoqi@0 458 Node* pop_node(BasicType n_type) {
aoqi@0 459 int n_size = type2size[n_type];
aoqi@0 460 if (n_size == 1) return pop();
aoqi@0 461 else if (n_size == 2) return pop_pair();
aoqi@0 462 else return NULL;
aoqi@0 463 }
aoqi@0 464
aoqi@0 465 Node* control() const { return map_not_null()->control(); }
aoqi@0 466 Node* i_o() const { return map_not_null()->i_o(); }
aoqi@0 467 Node* returnadr() const { return map_not_null()->returnadr(); }
aoqi@0 468 Node* frameptr() const { return map_not_null()->frameptr(); }
aoqi@0 469 Node* local(uint idx) const { map_not_null(); return _map->local( _map->_jvms, idx); }
aoqi@0 470 Node* stack(uint idx) const { map_not_null(); return _map->stack( _map->_jvms, idx); }
aoqi@0 471 Node* argument(uint idx) const { map_not_null(); return _map->argument( _map->_jvms, idx); }
aoqi@0 472 Node* monitor_box(uint idx) const { map_not_null(); return _map->monitor_box(_map->_jvms, idx); }
aoqi@0 473 Node* monitor_obj(uint idx) const { map_not_null(); return _map->monitor_obj(_map->_jvms, idx); }
aoqi@0 474
aoqi@0 475 void set_control (Node* c) { map_not_null()->set_control(c); }
aoqi@0 476 void set_i_o (Node* c) { map_not_null()->set_i_o(c); }
aoqi@0 477 void set_local(uint idx, Node* c) { map_not_null(); _map->set_local( _map->_jvms, idx, c); }
aoqi@0 478 void set_stack(uint idx, Node* c) { map_not_null(); _map->set_stack( _map->_jvms, idx, c); }
aoqi@0 479 void set_argument(uint idx, Node* c){ map_not_null(); _map->set_argument(_map->_jvms, idx, c); }
aoqi@0 480 void ensure_stack(uint stk_size) { map_not_null(); _map->ensure_stack(_map->_jvms, stk_size); }
aoqi@0 481
aoqi@0 482 // Access unaliased memory
aoqi@0 483 Node* memory(uint alias_idx);
aoqi@0 484 Node* memory(const TypePtr *tp) { return memory(C->get_alias_index(tp)); }
aoqi@0 485 Node* memory(Node* adr) { return memory(_gvn.type(adr)->is_ptr()); }
aoqi@0 486
aoqi@0 487 // Access immutable memory
aoqi@0 488 Node* immutable_memory() { return C->immutable_memory(); }
aoqi@0 489
aoqi@0 490 // Set unaliased memory
aoqi@0 491 void set_memory(Node* c, uint alias_idx) { merged_memory()->set_memory_at(alias_idx, c); }
aoqi@0 492 void set_memory(Node* c, const TypePtr *tp) { set_memory(c,C->get_alias_index(tp)); }
aoqi@0 493 void set_memory(Node* c, Node* adr) { set_memory(c,_gvn.type(adr)->is_ptr()); }
aoqi@0 494
aoqi@0 495 // Get the entire memory state (probably a MergeMemNode), and reset it
aoqi@0 496 // (The resetting prevents somebody from using the dangling Node pointer.)
aoqi@0 497 Node* reset_memory();
aoqi@0 498
aoqi@0 499 // Get the entire memory state, asserted to be a MergeMemNode.
aoqi@0 500 MergeMemNode* merged_memory() {
aoqi@0 501 Node* mem = map_not_null()->memory();
aoqi@0 502 assert(mem->is_MergeMem(), "parse memory is always pre-split");
aoqi@0 503 return mem->as_MergeMem();
aoqi@0 504 }
aoqi@0 505
aoqi@0 506 // Set the entire memory state; produce a new MergeMemNode.
aoqi@0 507 void set_all_memory(Node* newmem);
aoqi@0 508
aoqi@0 509 // Create a memory projection from the call, then set_all_memory.
aoqi@0 510 void set_all_memory_call(Node* call, bool separate_io_proj = false);
aoqi@0 511
aoqi@0 512 // Create a LoadNode, reading from the parser's memory state.
aoqi@0 513 // (Note: require_atomic_access is useful only with T_LONG.)
aoqi@0 514 //
aoqi@0 515 // We choose the unordered semantics by default because we have
aoqi@0 516 // adapted the `do_put_xxx' and `do_get_xxx' procedures for the case
aoqi@0 517 // of volatile fields.
aoqi@0 518 Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt,
aoqi@0 519 MemNode::MemOrd mo, bool require_atomic_access = false) {
aoqi@0 520 // This version computes alias_index from bottom_type
aoqi@0 521 return make_load(ctl, adr, t, bt, adr->bottom_type()->is_ptr(),
aoqi@0 522 mo, require_atomic_access);
aoqi@0 523 }
aoqi@0 524 Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt, const TypePtr* adr_type,
aoqi@0 525 MemNode::MemOrd mo, bool require_atomic_access = false) {
aoqi@0 526 // This version computes alias_index from an address type
aoqi@0 527 assert(adr_type != NULL, "use other make_load factory");
aoqi@0 528 return make_load(ctl, adr, t, bt, C->get_alias_index(adr_type),
aoqi@0 529 mo, require_atomic_access);
aoqi@0 530 }
aoqi@0 531 // This is the base version which is given an alias index.
aoqi@0 532 Node* make_load(Node* ctl, Node* adr, const Type* t, BasicType bt, int adr_idx,
aoqi@0 533 MemNode::MemOrd mo, bool require_atomic_access = false);
aoqi@0 534
aoqi@0 535 // Create & transform a StoreNode and store the effect into the
aoqi@0 536 // parser's memory state.
aoqi@0 537 //
aoqi@0 538 // We must ensure that stores of object references will be visible
aoqi@0 539 // only after the object's initialization. So the clients of this
aoqi@0 540 // procedure must indicate that the store requires `release'
aoqi@0 541 // semantics, if the stored value is an object reference that might
aoqi@0 542 // point to a new object and may become externally visible.
aoqi@0 543 Node* store_to_memory(Node* ctl, Node* adr, Node* val, BasicType bt,
aoqi@0 544 const TypePtr* adr_type,
aoqi@0 545 MemNode::MemOrd mo,
aoqi@0 546 bool require_atomic_access = false) {
aoqi@0 547 // This version computes alias_index from an address type
aoqi@0 548 assert(adr_type != NULL, "use other store_to_memory factory");
aoqi@0 549 return store_to_memory(ctl, adr, val, bt,
aoqi@0 550 C->get_alias_index(adr_type),
aoqi@0 551 mo, require_atomic_access);
aoqi@0 552 }
aoqi@0 553 // This is the base version which is given alias index
aoqi@0 554 // Return the new StoreXNode
aoqi@0 555 Node* store_to_memory(Node* ctl, Node* adr, Node* val, BasicType bt,
aoqi@0 556 int adr_idx,
aoqi@0 557 MemNode::MemOrd,
aoqi@0 558 bool require_atomic_access = false);
aoqi@0 559
aoqi@0 560
aoqi@0 561 // All in one pre-barrier, store, post_barrier
aoqi@0 562 // Insert a write-barrier'd store. This is to let generational GC
aoqi@0 563 // work; we have to flag all oop-stores before the next GC point.
aoqi@0 564 //
aoqi@0 565 // It comes in 3 flavors of store to an object, array, or unknown.
aoqi@0 566 // We use precise card marks for arrays to avoid scanning the entire
aoqi@0 567 // array. We use imprecise for object. We use precise for unknown
aoqi@0 568 // since we don't know if we have an array or and object or even
aoqi@0 569 // where the object starts.
aoqi@0 570 //
aoqi@0 571 // If val==NULL, it is taken to be a completely unknown value. QQQ
aoqi@0 572
aoqi@0 573 Node* store_oop(Node* ctl,
aoqi@0 574 Node* obj, // containing obj
aoqi@0 575 Node* adr, // actual adress to store val at
aoqi@0 576 const TypePtr* adr_type,
aoqi@0 577 Node* val,
aoqi@0 578 const TypeOopPtr* val_type,
aoqi@0 579 BasicType bt,
aoqi@0 580 bool use_precise,
aoqi@0 581 MemNode::MemOrd mo);
aoqi@0 582
aoqi@0 583 Node* store_oop_to_object(Node* ctl,
aoqi@0 584 Node* obj, // containing obj
aoqi@0 585 Node* adr, // actual adress to store val at
aoqi@0 586 const TypePtr* adr_type,
aoqi@0 587 Node* val,
aoqi@0 588 const TypeOopPtr* val_type,
aoqi@0 589 BasicType bt,
aoqi@0 590 MemNode::MemOrd mo) {
aoqi@0 591 return store_oop(ctl, obj, adr, adr_type, val, val_type, bt, false, mo);
aoqi@0 592 }
aoqi@0 593
aoqi@0 594 Node* store_oop_to_array(Node* ctl,
aoqi@0 595 Node* obj, // containing obj
aoqi@0 596 Node* adr, // actual adress to store val at
aoqi@0 597 const TypePtr* adr_type,
aoqi@0 598 Node* val,
aoqi@0 599 const TypeOopPtr* val_type,
aoqi@0 600 BasicType bt,
aoqi@0 601 MemNode::MemOrd mo) {
aoqi@0 602 return store_oop(ctl, obj, adr, adr_type, val, val_type, bt, true, mo);
aoqi@0 603 }
aoqi@0 604
aoqi@0 605 // Could be an array or object we don't know at compile time (unsafe ref.)
aoqi@0 606 Node* store_oop_to_unknown(Node* ctl,
aoqi@0 607 Node* obj, // containing obj
aoqi@0 608 Node* adr, // actual adress to store val at
aoqi@0 609 const TypePtr* adr_type,
aoqi@0 610 Node* val,
aoqi@0 611 BasicType bt,
aoqi@0 612 MemNode::MemOrd mo);
aoqi@0 613
aoqi@0 614 // For the few case where the barriers need special help
aoqi@0 615 void pre_barrier(bool do_load, Node* ctl,
aoqi@0 616 Node* obj, Node* adr, uint adr_idx, Node* val, const TypeOopPtr* val_type,
aoqi@0 617 Node* pre_val,
aoqi@0 618 BasicType bt);
aoqi@0 619
aoqi@0 620 void post_barrier(Node* ctl, Node* store, Node* obj, Node* adr, uint adr_idx,
aoqi@0 621 Node* val, BasicType bt, bool use_precise);
aoqi@0 622
aoqi@0 623 // Return addressing for an array element.
aoqi@0 624 Node* array_element_address(Node* ary, Node* idx, BasicType elembt,
aoqi@0 625 // Optional constraint on the array size:
aoqi@0 626 const TypeInt* sizetype = NULL);
aoqi@0 627
aoqi@0 628 // Return a load of array element at idx.
aoqi@0 629 Node* load_array_element(Node* ctl, Node* ary, Node* idx, const TypeAryPtr* arytype);
aoqi@0 630
aoqi@0 631 //---------------- Dtrace support --------------------
aoqi@0 632 void make_dtrace_method_entry_exit(ciMethod* method, bool is_entry);
aoqi@0 633 void make_dtrace_method_entry(ciMethod* method) {
aoqi@0 634 make_dtrace_method_entry_exit(method, true);
aoqi@0 635 }
aoqi@0 636 void make_dtrace_method_exit(ciMethod* method) {
aoqi@0 637 make_dtrace_method_entry_exit(method, false);
aoqi@0 638 }
aoqi@0 639
aoqi@0 640 //--------------- stub generation -------------------
aoqi@0 641 public:
aoqi@0 642 void gen_stub(address C_function,
aoqi@0 643 const char *name,
aoqi@0 644 int is_fancy_jump,
aoqi@0 645 bool pass_tls,
aoqi@0 646 bool return_pc);
aoqi@0 647
aoqi@0 648 //---------- help for generating calls --------------
aoqi@0 649
aoqi@0 650 // Do a null check on the receiver as it would happen before the call to
aoqi@0 651 // callee (with all arguments still on the stack).
aoqi@0 652 Node* null_check_receiver_before_call(ciMethod* callee) {
aoqi@0 653 assert(!callee->is_static(), "must be a virtual method");
aoqi@0 654 const int nargs = callee->arg_size();
aoqi@0 655 inc_sp(nargs);
aoqi@0 656 Node* n = null_check_receiver();
aoqi@0 657 dec_sp(nargs);
aoqi@0 658 return n;
aoqi@0 659 }
aoqi@0 660
aoqi@0 661 // Fill in argument edges for the call from argument(0), argument(1), ...
aoqi@0 662 // (The next step is to call set_edges_for_java_call.)
aoqi@0 663 void set_arguments_for_java_call(CallJavaNode* call);
aoqi@0 664
aoqi@0 665 // Fill in non-argument edges for the call.
aoqi@0 666 // Transform the call, and update the basics: control, i_o, memory.
aoqi@0 667 // (The next step is usually to call set_results_for_java_call.)
aoqi@0 668 void set_edges_for_java_call(CallJavaNode* call,
aoqi@0 669 bool must_throw = false, bool separate_io_proj = false);
aoqi@0 670
aoqi@0 671 // Finish up a java call that was started by set_edges_for_java_call.
aoqi@0 672 // Call add_exception on any throw arising from the call.
aoqi@0 673 // Return the call result (transformed).
aoqi@0 674 Node* set_results_for_java_call(CallJavaNode* call, bool separate_io_proj = false);
aoqi@0 675
aoqi@0 676 // Similar to set_edges_for_java_call, but simplified for runtime calls.
aoqi@0 677 void set_predefined_output_for_runtime_call(Node* call) {
aoqi@0 678 set_predefined_output_for_runtime_call(call, NULL, NULL);
aoqi@0 679 }
aoqi@0 680 void set_predefined_output_for_runtime_call(Node* call,
aoqi@0 681 Node* keep_mem,
aoqi@0 682 const TypePtr* hook_mem);
aoqi@0 683 Node* set_predefined_input_for_runtime_call(SafePointNode* call);
aoqi@0 684
aoqi@0 685 // Replace the call with the current state of the kit. Requires
aoqi@0 686 // that the call was generated with separate io_projs so that
aoqi@0 687 // exceptional control flow can be handled properly.
aoqi@0 688 void replace_call(CallNode* call, Node* result);
aoqi@0 689
aoqi@0 690 // helper functions for statistics
aoqi@0 691 void increment_counter(address counter_addr); // increment a debug counter
aoqi@0 692 void increment_counter(Node* counter_addr); // increment a debug counter
aoqi@0 693
aoqi@0 694 // Bail out to the interpreter right now
aoqi@0 695 // The optional klass is the one causing the trap.
aoqi@0 696 // The optional reason is debug information written to the compile log.
aoqi@0 697 // Optional must_throw is the same as with add_safepoint_edges.
aoqi@0 698 void uncommon_trap(int trap_request,
aoqi@0 699 ciKlass* klass = NULL, const char* reason_string = NULL,
aoqi@0 700 bool must_throw = false, bool keep_exact_action = false);
aoqi@0 701
aoqi@0 702 // Shorthand, to avoid saying "Deoptimization::" so many times.
aoqi@0 703 void uncommon_trap(Deoptimization::DeoptReason reason,
aoqi@0 704 Deoptimization::DeoptAction action,
aoqi@0 705 ciKlass* klass = NULL, const char* reason_string = NULL,
aoqi@0 706 bool must_throw = false, bool keep_exact_action = false) {
aoqi@0 707 uncommon_trap(Deoptimization::make_trap_request(reason, action),
aoqi@0 708 klass, reason_string, must_throw, keep_exact_action);
aoqi@0 709 }
aoqi@0 710
aoqi@0 711 // SP when bytecode needs to be reexecuted.
aoqi@0 712 virtual int reexecute_sp() { return sp(); }
aoqi@0 713
aoqi@0 714 // Report if there were too many traps at the current method and bci.
aoqi@0 715 // Report if a trap was recorded, and/or PerMethodTrapLimit was exceeded.
aoqi@0 716 // If there is no MDO at all, report no trap unless told to assume it.
aoqi@0 717 bool too_many_traps(Deoptimization::DeoptReason reason) {
aoqi@0 718 return C->too_many_traps(method(), bci(), reason);
aoqi@0 719 }
aoqi@0 720
aoqi@0 721 // Report if there were too many recompiles at the current method and bci.
aoqi@0 722 bool too_many_recompiles(Deoptimization::DeoptReason reason) {
aoqi@0 723 return C->too_many_recompiles(method(), bci(), reason);
aoqi@0 724 }
aoqi@0 725
aoqi@0 726 // Returns the object (if any) which was created the moment before.
aoqi@0 727 Node* just_allocated_object(Node* current_control);
aoqi@0 728
aoqi@0 729 static bool use_ReduceInitialCardMarks() {
aoqi@0 730 return (ReduceInitialCardMarks
aoqi@0 731 && Universe::heap()->can_elide_tlab_store_barriers());
aoqi@0 732 }
aoqi@0 733
aoqi@0 734 // Sync Ideal and Graph kits.
aoqi@0 735 void sync_kit(IdealKit& ideal);
aoqi@0 736 void final_sync(IdealKit& ideal);
aoqi@0 737
aoqi@0 738 // vanilla/CMS post barrier
aoqi@0 739 void write_barrier_post(Node *store, Node* obj,
aoqi@0 740 Node* adr, uint adr_idx, Node* val, bool use_precise);
aoqi@0 741
aoqi@0 742 // Allow reordering of pre-barrier with oop store and/or post-barrier.
aoqi@0 743 // Used for load_store operations which loads old value.
aoqi@0 744 bool can_move_pre_barrier() const;
aoqi@0 745
aoqi@0 746 // G1 pre/post barriers
aoqi@0 747 void g1_write_barrier_pre(bool do_load,
aoqi@0 748 Node* obj,
aoqi@0 749 Node* adr,
aoqi@0 750 uint alias_idx,
aoqi@0 751 Node* val,
aoqi@0 752 const TypeOopPtr* val_type,
aoqi@0 753 Node* pre_val,
aoqi@0 754 BasicType bt);
aoqi@0 755
aoqi@0 756 void g1_write_barrier_post(Node* store,
aoqi@0 757 Node* obj,
aoqi@0 758 Node* adr,
aoqi@0 759 uint alias_idx,
aoqi@0 760 Node* val,
aoqi@0 761 BasicType bt,
aoqi@0 762 bool use_precise);
aoqi@0 763 // Helper function for g1
aoqi@0 764 private:
aoqi@0 765 void g1_mark_card(IdealKit& ideal, Node* card_adr, Node* store, uint oop_alias_idx,
aoqi@0 766 Node* index, Node* index_adr,
aoqi@0 767 Node* buffer, const TypeFunc* tf);
aoqi@0 768
aoqi@0 769 public:
aoqi@0 770 // Helper function to round double arguments before a call
aoqi@0 771 void round_double_arguments(ciMethod* dest_method);
aoqi@0 772 void round_double_result(ciMethod* dest_method);
aoqi@0 773
aoqi@0 774 // rounding for strict float precision conformance
aoqi@0 775 Node* precision_rounding(Node* n);
aoqi@0 776
aoqi@0 777 // rounding for strict double precision conformance
aoqi@0 778 Node* dprecision_rounding(Node* n);
aoqi@0 779
aoqi@0 780 // rounding for non-strict double stores
aoqi@0 781 Node* dstore_rounding(Node* n);
aoqi@0 782
aoqi@0 783 // Helper functions for fast/slow path codes
aoqi@0 784 Node* opt_iff(Node* region, Node* iff);
aoqi@0 785 Node* make_runtime_call(int flags,
aoqi@0 786 const TypeFunc* call_type, address call_addr,
aoqi@0 787 const char* call_name,
aoqi@0 788 const TypePtr* adr_type, // NULL if no memory effects
aoqi@0 789 Node* parm0 = NULL, Node* parm1 = NULL,
aoqi@0 790 Node* parm2 = NULL, Node* parm3 = NULL,
aoqi@0 791 Node* parm4 = NULL, Node* parm5 = NULL,
aoqi@0 792 Node* parm6 = NULL, Node* parm7 = NULL);
aoqi@0 793 enum { // flag values for make_runtime_call
aoqi@0 794 RC_NO_FP = 1, // CallLeafNoFPNode
aoqi@0 795 RC_NO_IO = 2, // do not hook IO edges
aoqi@0 796 RC_NO_LEAF = 4, // CallStaticJavaNode
aoqi@0 797 RC_MUST_THROW = 8, // flag passed to add_safepoint_edges
aoqi@0 798 RC_NARROW_MEM = 16, // input memory is same as output
aoqi@0 799 RC_UNCOMMON = 32, // freq. expected to be like uncommon trap
aoqi@0 800 RC_LEAF = 0 // null value: no flags set
aoqi@0 801 };
aoqi@0 802
aoqi@0 803 // merge in all memory slices from new_mem, along the given path
aoqi@0 804 void merge_memory(Node* new_mem, Node* region, int new_path);
aoqi@0 805 void make_slow_call_ex(Node* call, ciInstanceKlass* ex_klass, bool separate_io_proj, bool deoptimize = false);
aoqi@0 806
aoqi@0 807 // Helper functions to build synchronizations
aoqi@0 808 int next_monitor();
aoqi@0 809 Node* insert_mem_bar(int opcode, Node* precedent = NULL);
aoqi@0 810 Node* insert_mem_bar_volatile(int opcode, int alias_idx, Node* precedent = NULL);
aoqi@0 811 // Optional 'precedent' is appended as an extra edge, to force ordering.
aoqi@0 812 FastLockNode* shared_lock(Node* obj);
aoqi@0 813 void shared_unlock(Node* box, Node* obj);
aoqi@0 814
aoqi@0 815 // helper functions for the fast path/slow path idioms
aoqi@0 816 Node* fast_and_slow(Node* in, const Type *result_type, Node* null_result, IfNode* fast_test, Node* fast_result, address slow_call, const TypeFunc *slow_call_type, Node* slow_arg, Klass* ex_klass, Node* slow_result);
aoqi@0 817
aoqi@0 818 // Generate an instance-of idiom. Used by both the instance-of bytecode
aoqi@0 819 // and the reflective instance-of call.
aoqi@0 820 Node* gen_instanceof(Node *subobj, Node* superkls, bool safe_for_replace = false);
aoqi@0 821
aoqi@0 822 // Generate a check-cast idiom. Used by both the check-cast bytecode
aoqi@0 823 // and the array-store bytecode
aoqi@0 824 Node* gen_checkcast( Node *subobj, Node* superkls,
aoqi@0 825 Node* *failure_control = NULL );
aoqi@0 826
aoqi@0 827 // Generate a subtyping check. Takes as input the subtype and supertype.
aoqi@0 828 // Returns 2 values: sets the default control() to the true path and
aoqi@0 829 // returns the false path. Only reads from constant memory taken from the
aoqi@0 830 // default memory; does not write anything. It also doesn't take in an
aoqi@0 831 // Object; if you wish to check an Object you need to load the Object's
aoqi@0 832 // class prior to coming here.
aoqi@0 833 Node* gen_subtype_check(Node* subklass, Node* superklass);
aoqi@0 834
aoqi@0 835 // Static parse-time type checking logic for gen_subtype_check:
aoqi@0 836 enum { SSC_always_false, SSC_always_true, SSC_easy_test, SSC_full_test };
aoqi@0 837 int static_subtype_check(ciKlass* superk, ciKlass* subk);
aoqi@0 838
aoqi@0 839 // Exact type check used for predicted calls and casts.
aoqi@0 840 // Rewrites (*casted_receiver) to be casted to the stronger type.
aoqi@0 841 // (Caller is responsible for doing replace_in_map.)
aoqi@0 842 Node* type_check_receiver(Node* receiver, ciKlass* klass, float prob,
aoqi@0 843 Node* *casted_receiver);
aoqi@0 844
aoqi@0 845 // implementation of object creation
aoqi@0 846 Node* set_output_for_allocation(AllocateNode* alloc,
aoqi@0 847 const TypeOopPtr* oop_type,
aoqi@0 848 bool deoptimize_on_exception=false);
aoqi@0 849 Node* get_layout_helper(Node* klass_node, jint& constant_value);
aoqi@0 850 Node* new_instance(Node* klass_node,
aoqi@0 851 Node* slow_test = NULL,
aoqi@0 852 Node* *return_size_val = NULL,
aoqi@0 853 bool deoptimize_on_exception = false);
aoqi@0 854 Node* new_array(Node* klass_node, Node* count_val, int nargs,
aoqi@0 855 Node* *return_size_val = NULL,
aoqi@0 856 bool deoptimize_on_exception = false);
aoqi@0 857
aoqi@0 858 // java.lang.String helpers
aoqi@0 859 Node* load_String_offset(Node* ctrl, Node* str);
aoqi@0 860 Node* load_String_length(Node* ctrl, Node* str);
aoqi@0 861 Node* load_String_value(Node* ctrl, Node* str);
aoqi@0 862 void store_String_offset(Node* ctrl, Node* str, Node* value);
aoqi@0 863 void store_String_length(Node* ctrl, Node* str, Node* value);
aoqi@0 864 void store_String_value(Node* ctrl, Node* str, Node* value);
aoqi@0 865
aoqi@0 866 // Handy for making control flow
aoqi@0 867 IfNode* create_and_map_if(Node* ctrl, Node* tst, float prob, float cnt) {
aoqi@0 868 IfNode* iff = new (C) IfNode(ctrl, tst, prob, cnt);// New IfNode's
aoqi@0 869 _gvn.set_type(iff, iff->Value(&_gvn)); // Value may be known at parse-time
aoqi@0 870 // Place 'if' on worklist if it will be in graph
aoqi@0 871 if (!tst->is_Con()) record_for_igvn(iff); // Range-check and Null-check removal is later
aoqi@0 872 return iff;
aoqi@0 873 }
aoqi@0 874
aoqi@0 875 IfNode* create_and_xform_if(Node* ctrl, Node* tst, float prob, float cnt) {
aoqi@0 876 IfNode* iff = new (C) IfNode(ctrl, tst, prob, cnt);// New IfNode's
aoqi@0 877 _gvn.transform(iff); // Value may be known at parse-time
aoqi@0 878 // Place 'if' on worklist if it will be in graph
aoqi@0 879 if (!tst->is_Con()) record_for_igvn(iff); // Range-check and Null-check removal is later
aoqi@0 880 return iff;
aoqi@0 881 }
aoqi@0 882
aoqi@0 883 // Insert a loop predicate into the graph
aoqi@0 884 void add_predicate(int nargs = 0);
aoqi@0 885 void add_predicate_impl(Deoptimization::DeoptReason reason, int nargs);
aoqi@0 886
aoqi@0 887 // Produce new array node of stable type
aoqi@0 888 Node* cast_array_to_stable(Node* ary, const TypeAryPtr* ary_type);
aoqi@0 889 };
aoqi@0 890
aoqi@0 891 // Helper class to support building of control flow branches. Upon
aoqi@0 892 // creation the map and sp at bci are cloned and restored upon de-
aoqi@0 893 // struction. Typical use:
aoqi@0 894 //
aoqi@0 895 // { PreserveJVMState pjvms(this);
aoqi@0 896 // // code of new branch
aoqi@0 897 // }
aoqi@0 898 // // here the JVM state at bci is established
aoqi@0 899
aoqi@0 900 class PreserveJVMState: public StackObj {
aoqi@0 901 protected:
aoqi@0 902 GraphKit* _kit;
aoqi@0 903 #ifdef ASSERT
aoqi@0 904 int _block; // PO of current block, if a Parse
aoqi@0 905 int _bci;
aoqi@0 906 #endif
aoqi@0 907 SafePointNode* _map;
aoqi@0 908 uint _sp;
aoqi@0 909
aoqi@0 910 public:
aoqi@0 911 PreserveJVMState(GraphKit* kit, bool clone_map = true);
aoqi@0 912 ~PreserveJVMState();
aoqi@0 913 };
aoqi@0 914
aoqi@0 915 // Helper class to build cutouts of the form if (p) ; else {x...}.
aoqi@0 916 // The code {x...} must not fall through.
aoqi@0 917 // The kit's main flow of control is set to the "then" continuation of if(p).
aoqi@0 918 class BuildCutout: public PreserveJVMState {
aoqi@0 919 public:
aoqi@0 920 BuildCutout(GraphKit* kit, Node* p, float prob, float cnt = COUNT_UNKNOWN);
aoqi@0 921 ~BuildCutout();
aoqi@0 922 };
aoqi@0 923
aoqi@0 924 // Helper class to preserve the original _reexecute bit and _sp and restore
aoqi@0 925 // them back
aoqi@0 926 class PreserveReexecuteState: public StackObj {
aoqi@0 927 protected:
aoqi@0 928 GraphKit* _kit;
aoqi@0 929 uint _sp;
aoqi@0 930 JVMState::ReexecuteState _reexecute;
aoqi@0 931
aoqi@0 932 public:
aoqi@0 933 PreserveReexecuteState(GraphKit* kit);
aoqi@0 934 ~PreserveReexecuteState();
aoqi@0 935 };
aoqi@0 936
aoqi@0 937 #endif // SHARE_VM_OPTO_GRAPHKIT_HPP

mercurial