1 #ifdef USE_PRAGMA_IDENT_SRC
2 #pragma ident "@(#)graphKit.cpp 1.132 07/10/04 14:36:00 JVM"
3 #endif
4 /*
5 * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved.
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 *
8 * This code is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 only, as
10 * published by the Free Software Foundation.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
24 * have any questions.
25 *
518 ex_obj = env()->ArithmeticException_instance();
519 break;
520 case Deoptimization::Reason_range_check:
521 ex_obj = env()->ArrayIndexOutOfBoundsException_instance();
522 break;
523 case Deoptimization::Reason_class_check:
524 if (java_bc() == Bytecodes::_aastore) {
525 ex_obj = env()->ArrayStoreException_instance();
526 } else {
527 ex_obj = env()->ClassCastException_instance();
528 }
529 break;
530 }
531 if (failing()) { stop(); return; } // exception allocation might fail
532 if (ex_obj != NULL) {
533 // Cheat with a preallocated exception object.
534 if (C->log() != NULL)
535 C->log()->elem("hot_throw preallocated='1' reason='%s'",
536 Deoptimization::trap_reason_name(reason));
537 const TypeInstPtr* ex_con = TypeInstPtr::make(ex_obj);
538 Node* ex_node = _gvn.transform(new (C, 1) ConPNode(ex_con));
539
540 // Clear the detail message of the preallocated exception object.
541 // Weblogic sometimes mutates the detail message of exceptions
542 // using reflection.
543 int offset = java_lang_Throwable::get_detailMessage_offset();
544 const TypePtr* adr_typ = ex_con->add_offset(offset);
545
546 Node *adr = basic_plus_adr(ex_node, ex_node, offset);
547 Node *store = store_oop_to_object(control(), ex_node, adr, adr_typ, null(), ex_con, T_OBJECT);
548
549 add_exception_state(make_exception_state(ex_node));
550 return;
551 }
552 }
553
554 // %%% Maybe add entry to OptoRuntime which directly throws the exc.?
555 // It won't be much cheaper than bailing to the interp., since we'll
556 // have to pass up all the debug-info, and the runtime will have to
557 // create the stack trace.
558
573
574 // "must_throw" prunes the JVM state to include only the stack, if there
575 // are no local exception handlers. This should cut down on register
576 // allocation time and code size, by drastically reducing the number
577 // of in-edges on the call to the uncommon trap.
578
579 uncommon_trap(reason, action, (ciKlass*)NULL, (char*)NULL, must_throw);
580 }
581
582
583 //----------------------------PreserveJVMState---------------------------------
584 PreserveJVMState::PreserveJVMState(GraphKit* kit, bool clone_map) {
585 debug_only(kit->verify_map());
586 _kit = kit;
587 _map = kit->map(); // preserve the map
588 _sp = kit->sp();
589 kit->set_map(clone_map ? kit->clone_map() : NULL);
590 #ifdef ASSERT
591 _bci = kit->bci();
592 Parse* parser = kit->is_Parse();
593 int block = (parser == NULL || parser->block() == NULL) ? -1 : parser->block()->pre_order();
594 _block = block;
595 #endif
596 }
597 PreserveJVMState::~PreserveJVMState() {
598 GraphKit* kit = _kit;
599 #ifdef ASSERT
600 assert(kit->bci() == _bci, "bci must not shift");
601 Parse* parser = kit->is_Parse();
602 int block = (parser == NULL || parser->block() == NULL) ? -1 : parser->block()->pre_order();
603 assert(block == _block, "block must not shift");
604 #endif
605 kit->set_map(_map);
606 kit->set_sp(_sp);
607 }
608
609
610 //-----------------------------BuildCutout-------------------------------------
611 BuildCutout::BuildCutout(GraphKit* kit, Node* p, float prob, float cnt)
612 : PreserveJVMState(kit)
613 {
614 assert(p->is_Con() || p->is_Bool(), "test must be a bool");
615 SafePointNode* outer_map = _map; // preserved map is caller's
616 SafePointNode* inner_map = kit->map();
617 IfNode* iff = kit->create_and_map_if(outer_map->control(), p, prob, cnt);
618 outer_map->set_control(kit->gvn().transform( new (kit->C, 1) IfTrueNode(iff) ));
619 inner_map->set_control(kit->gvn().transform( new (kit->C, 1) IfFalseNode(iff) ));
620 }
621 BuildCutout::~BuildCutout() {
622 GraphKit* kit = _kit;
843 } else if (can_prune_locals && stack_slots_not_pruned != 0) {
844 // Divide stack into {S0,...,S1}, where S0 is set to top.
845 uint s1 = stack_slots_not_pruned;
846 stack_slots_not_pruned = 0; // for next iteration
847 if (s1 > l) s1 = l;
848 uint s0 = l - s1;
849 p += s0; // skip the tops preinstalled by add_req_batch
850 for (j = s0; j < l; j++)
851 call->set_req(p++, in_map->in(k+j));
852 } else {
853 p += l; // already set to top above by add_req_batch
854 }
855
856 // Add the Monitors
857 k = in_jvms->monoff();
858 l = in_jvms->mon_size();
859 out_jvms->set_monoff(p);
860 for (j = 0; j < l; j++)
861 call->set_req(p++, in_map->in(k+j));
862
863 // Finish the new jvms.
864 out_jvms->set_endoff(p);
865
866 assert(out_jvms->endoff() == debug_end, "fill ptr must match");
867 assert(out_jvms->depth() == in_jvms->depth(), "depth must match");
868 assert(out_jvms->loc_size() == in_jvms->loc_size(), "size must match");
869 assert(out_jvms->mon_size() == in_jvms->mon_size(), "size must match");
870 assert(out_jvms->debug_size() == in_jvms->debug_size(), "size must match");
871
872 // Update the two tail pointers in parallel.
873 out_jvms = out_jvms->caller();
874 in_jvms = in_jvms->caller();
875 }
876
877 assert(debug_ptr == non_debug_edges, "debug info must fit exactly");
878
879 // Test the correctness of JVMState::debug_xxx accessors:
880 assert(call->jvms()->debug_start() == non_debug_edges, "");
881 assert(call->jvms()->debug_end() == call->req(), "");
882 assert(call->jvms()->debug_depth() == call->req() - non_debug_edges, "");
883 }
884
885 bool GraphKit::compute_stack_effects(int& inputs, int& depth) {
886 Bytecodes::Code code = java_bc();
887 if (code == Bytecodes::_wide) {
888 code = method()->java_code_at_bci(bci() + 1);
889 }
1021 if (offset_con != Type::OffsetBot) {
1022 return longcon((long) offset_con);
1023 }
1024 return _gvn.transform( new (C, 2) ConvI2LNode(offset));
1025 }
1026 Node* GraphKit::ConvL2I(Node* offset) {
1027 // short-circuit a common case
1028 jlong offset_con = find_long_con(offset, (jlong)Type::OffsetBot);
1029 if (offset_con != (jlong)Type::OffsetBot) {
1030 return intcon((int) offset_con);
1031 }
1032 return _gvn.transform( new (C, 2) ConvL2INode(offset));
1033 }
1034
1035 //-------------------------load_object_klass-----------------------------------
1036 Node* GraphKit::load_object_klass(Node* obj) {
1037 // Special-case a fresh allocation to avoid building nodes:
1038 Node* akls = AllocateNode::Ideal_klass(obj, &_gvn);
1039 if (akls != NULL) return akls;
1040 Node* k_adr = basic_plus_adr(obj, oopDesc::klass_offset_in_bytes());
1041 return _gvn.transform( new (C, 3) LoadKlassNode(0, immutable_memory(), k_adr, TypeInstPtr::KLASS) );
1042 }
1043
1044 //-------------------------load_array_length-----------------------------------
1045 Node* GraphKit::load_array_length(Node* array) {
1046 // Special-case a fresh allocation to avoid building nodes:
1047 Node* alen = AllocateArrayNode::Ideal_length(array, &_gvn);
1048 if (alen != NULL) return alen;
1049 Node *r_adr = basic_plus_adr(array, arrayOopDesc::length_offset_in_bytes());
1050 return _gvn.transform( new (C, 3) LoadRangeNode(0, immutable_memory(), r_adr, TypeInt::POS));
1051 }
1052
1053 //------------------------------do_null_check----------------------------------
1054 // Helper function to do a NULL pointer check. Returned value is
1055 // the incoming address with NULL casted away. You are allowed to use the
1056 // not-null value only if you are control dependent on the test.
1057 extern int explicit_null_checks_inserted,
1058 explicit_null_checks_elided;
1059 Node* GraphKit::null_check_common(Node* value, BasicType type,
1060 // optional arguments for variations:
1061 bool assert_null,
1062 Node* *null_control) {
1063 assert(!assert_null || null_control == NULL, "not both at once");
1064 if (stopped()) return top();
1065 if (!GenerateCompilerNullChecks && !assert_null && null_control == NULL) {
1066 // For some performance testing, we may wish to suppress null checking.
1067 value = cast_not_null(value); // Make it appear to be non-null (4962416).
1068 return value;
1069 }
1070 explicit_null_checks_inserted++;
1158 explicit_null_checks_elided++;
1159 return res;
1160 }
1161 cfg = IfNode::up_one_dom(cfg, /*linear_only=*/ true);
1162 if (cfg == NULL) break; // Quit at region nodes
1163 depth++;
1164 }
1165 }
1166
1167 //-----------
1168 // Branch to failure if null
1169 float ok_prob = PROB_MAX; // a priori estimate: nulls never happen
1170 Deoptimization::DeoptReason reason;
1171 if (assert_null)
1172 reason = Deoptimization::Reason_null_assert;
1173 else if (type == T_OBJECT)
1174 reason = Deoptimization::Reason_null_check;
1175 else
1176 reason = Deoptimization::Reason_div0_check;
1177
1178 // To cause an implicit null check, we set the not-null probability
1179 // to the maximum (PROB_MAX). For an explicit check the probablity
1180 // is set to a smaller value.
1181 if (null_control != NULL || too_many_traps(reason)) {
1182 // probability is less likely
1183 ok_prob = PROB_LIKELY_MAG(3);
1184 } else if (!assert_null &&
1185 (ImplicitNullCheckThreshold > 0) &&
1186 method() != NULL &&
1187 (method()->method_data()->trap_count(reason)
1188 >= (uint)ImplicitNullCheckThreshold)) {
1189 ok_prob = PROB_LIKELY_MAG(3);
1190 }
1191
1192 if (null_control != NULL) {
1193 IfNode* iff = create_and_map_if(control(), tst, ok_prob, COUNT_UNKNOWN);
1194 Node* null_true = _gvn.transform( new (C, 1) IfFalseNode(iff));
1195 set_control( _gvn.transform( new (C, 1) IfTrueNode(iff)));
1196 if (null_true == top())
1197 explicit_null_checks_elided++;
1198 (*null_control) = null_true;
1199 } else {
1200 BuildCutout unless(this, tst, ok_prob);
1201 // Check for optimizer eliding test at parse time
1202 if (stopped()) {
1203 // Failure not possible; do not bother making uncommon trap.
1204 explicit_null_checks_elided++;
1205 } else if (assert_null) {
1206 uncommon_trap(reason,
1207 Deoptimization::Action_make_not_entrant,
1208 NULL, "assert_null");
1209 } else {
1210 builtin_throw(reason);
1211 }
1212 }
1213
1214 // Must throw exception, fall-thru not possible?
1215 if (stopped()) {
1216 return top(); // No result
1217 }
1218
1219 if (assert_null) {
1220 // Cast obj to null on this path.
1221 replace_in_map(value, zerocon(type));
1222 return zerocon(type);
1223 }
1224
1225 // Cast obj to not-null on this path, if there is no null_control.
1226 // (If there is a null_control, a non-null value may come back to haunt us.)
1227 if (type == T_OBJECT) {
1228 Node* cast = cast_not_null(value, false);
1229 if (null_control == NULL || (*null_control) == top())
1306 //=============================================================================
1307 //
1308 // parser factory methods for MemNodes
1309 //
1310 // These are layered on top of the factory methods in LoadNode and StoreNode,
1311 // and integrate with the parser's memory state and _gvn engine.
1312 //
1313
1314 // factory methods in "int adr_idx"
1315 Node* GraphKit::make_load(Node* ctl, Node* adr, const Type* t, BasicType bt,
1316 int adr_idx,
1317 bool require_atomic_access) {
1318 assert(adr_idx != Compile::AliasIdxTop, "use other make_load factory" );
1319 const TypePtr* adr_type = NULL; // debug-mode-only argument
1320 debug_only(adr_type = C->get_adr_type(adr_idx));
1321 Node* mem = memory(adr_idx);
1322 Node* ld;
1323 if (require_atomic_access && bt == T_LONG) {
1324 ld = LoadLNode::make_atomic(C, ctl, mem, adr, adr_type, t);
1325 } else {
1326 ld = LoadNode::make(C, ctl, mem, adr, adr_type, t, bt);
1327 }
1328 return _gvn.transform(ld);
1329 }
1330
1331 Node* GraphKit::store_to_memory(Node* ctl, Node* adr, Node *val, BasicType bt,
1332 int adr_idx,
1333 bool require_atomic_access) {
1334 assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory" );
1335 const TypePtr* adr_type = NULL;
1336 debug_only(adr_type = C->get_adr_type(adr_idx));
1337 Node *mem = memory(adr_idx);
1338 Node* st;
1339 if (require_atomic_access && bt == T_LONG) {
1340 st = StoreLNode::make_atomic(C, ctl, mem, adr, adr_type, val);
1341 } else {
1342 st = StoreNode::make(C, ctl, mem, adr, adr_type, val, bt);
1343 }
1344 st = _gvn.transform(st);
1345 set_memory(st, adr_idx);
1346 // Back-to-back stores can only remove intermediate store with DU info
1347 // so push on worklist for optimizer.
1348 if (mem->req() > MemNode::Address && adr == mem->in(MemNode::Address))
1349 record_for_igvn(st);
1350
1351 return st;
1352 }
1353
1354 void GraphKit::pre_barrier(Node* ctl,
1355 Node* obj,
1356 Node* adr,
1357 uint adr_idx,
1358 Node *val,
1359 const Type* val_type,
1360 BasicType bt) {
1361 BarrierSet* bs = Universe::heap()->barrier_set();
1362 set_control(ctl);
1363 switch (bs->kind()) {
1364
1365 case BarrierSet::CardTableModRef:
1366 case BarrierSet::CardTableExtension:
1367 case BarrierSet::ModRef:
1368 break;
1369
1370 case BarrierSet::Other:
1371 default :
1372 ShouldNotReachHere();
1373
1374 }
1375 }
1376
1377 void GraphKit::post_barrier(Node* ctl,
1378 Node* store,
1379 Node* obj,
1380 Node* adr,
1381 uint adr_idx,
1382 Node *val,
1383 BasicType bt,
1384 bool use_precise) {
1385 BarrierSet* bs = Universe::heap()->barrier_set();
1386 set_control(ctl);
1387 switch (bs->kind()) {
1388
1389 case BarrierSet::CardTableModRef:
1390 case BarrierSet::CardTableExtension:
1391 write_barrier_post(store, obj, adr, val, use_precise);
1392 break;
1393
1394 case BarrierSet::ModRef:
1395 break;
1396
1397 case BarrierSet::Other:
1398 default :
1399 ShouldNotReachHere();
1400
1401 }
1402 }
1403
1404 Node* GraphKit::store_oop_to_object(Node* ctl,
1405 Node* obj,
1406 Node* adr,
1407 const TypePtr* adr_type,
1433
1434 Node* GraphKit::store_oop_to_unknown(Node* ctl,
1435 Node* obj,
1436 Node* adr,
1437 const TypePtr* adr_type,
1438 Node *val,
1439 const Type* val_type,
1440 BasicType bt) {
1441 uint adr_idx = C->get_alias_index(adr_type);
1442 Node* store;
1443 pre_barrier(ctl, obj, adr, adr_idx, val, val_type, bt);
1444 store = store_to_memory(control(), adr, val, bt, adr_idx);
1445 post_barrier(control(), store, obj, adr, adr_idx, val, bt, true);
1446 return store;
1447 }
1448
1449
1450 //-------------------------array_element_address-------------------------
1451 Node* GraphKit::array_element_address(Node* ary, Node* idx, BasicType elembt,
1452 const TypeInt* sizetype) {
1453 uint shift = exact_log2(type2aelembytes[elembt]);
1454 uint header = arrayOopDesc::base_offset_in_bytes(elembt);
1455
1456 // short-circuit a common case (saves lots of confusing waste motion)
1457 jint idx_con = find_int_con(idx, -1);
1458 if (idx_con >= 0) {
1459 intptr_t offset = header + ((intptr_t)idx_con << shift);
1460 return basic_plus_adr(ary, offset);
1461 }
1462
1463 // must be correct type for alignment purposes
1464 Node* base = basic_plus_adr(ary, header);
1465 #ifdef _LP64
1466 // The scaled index operand to AddP must be a clean 64-bit value.
1467 // Java allows a 32-bit int to be incremented to a negative
1468 // value, which appears in a 64-bit register as a large
1469 // positive number. Using that large positive number as an
1470 // operand in pointer arithmetic has bad consequences.
1471 // On the other hand, 32-bit overflow is rare, and the possibility
1472 // can often be excluded, if we annotate the ConvI2L node with
1473 // a type assertion that its value is known to be a small positive
1938 // Code is structured as a series of driver functions all called 'do_XXX' that
1939 // call a set of helper functions. Helper functions first, then drivers.
1940
1941 //------------------------------null_check_oop---------------------------------
1942 // Null check oop. Set null-path control into Region in slot 3.
1943 // Make a cast-not-nullness use the other not-null control. Return cast.
1944 Node* GraphKit::null_check_oop(Node* value, Node* *null_control,
1945 bool never_see_null) {
1946 // Initial NULL check taken path
1947 (*null_control) = top();
1948 Node* cast = null_check_common(value, T_OBJECT, false, null_control);
1949
1950 // Generate uncommon_trap:
1951 if (never_see_null && (*null_control) != top()) {
1952 // If we see an unexpected null at a check-cast we record it and force a
1953 // recompile; the offending check-cast will be compiled to handle NULLs.
1954 // If we see more than one offending BCI, then all checkcasts in the
1955 // method will be compiled to handle NULLs.
1956 PreserveJVMState pjvms(this);
1957 set_control(*null_control);
1958 uncommon_trap(Deoptimization::Reason_null_check,
1959 Deoptimization::Action_make_not_entrant);
1960 (*null_control) = top(); // NULL path is dead
1961 }
1962
1963 // Cast away null-ness on the result
1964 return cast;
1965 }
1966
1967 //------------------------------opt_iff----------------------------------------
1968 // Optimize the fast-check IfNode. Set the fast-path region slot 2.
1969 // Return slow-path control.
1970 Node* GraphKit::opt_iff(Node* region, Node* iff) {
1971 IfNode *opt_iff = _gvn.transform(iff)->as_If();
1972
1973 // Fast path taken; set region slot 2
1974 Node *fast_taken = _gvn.transform( new (C, 1) IfFalseNode(opt_iff) );
1975 region->init_req(2,fast_taken); // Capture fast-control
1976
1977 // Fast path not-taken, i.e. slow path
2188 // will always succeed. We could leave a dependency behind to ensure this.
2189
2190 // First load the super-klass's check-offset
2191 Node *p1 = basic_plus_adr( superklass, superklass, sizeof(oopDesc) + Klass::super_check_offset_offset_in_bytes() );
2192 Node *chk_off = _gvn.transform( new (C, 3) LoadINode( NULL, memory(p1), p1, _gvn.type(p1)->is_ptr() ) );
2193 int cacheoff_con = sizeof(oopDesc) + Klass::secondary_super_cache_offset_in_bytes();
2194 bool might_be_cache = (find_int_con(chk_off, cacheoff_con) == cacheoff_con);
2195
2196 // Load from the sub-klass's super-class display list, or a 1-word cache of
2197 // the secondary superclass list, or a failing value with a sentinel offset
2198 // if the super-klass is an interface or exceptionally deep in the Java
2199 // hierarchy and we have to scan the secondary superclass list the hard way.
2200 // Worst-case type is a little odd: NULL is allowed as a result (usually
2201 // klass loads can never produce a NULL).
2202 Node *chk_off_X = ConvI2X(chk_off);
2203 Node *p2 = _gvn.transform( new (C, 4) AddPNode(subklass,subklass,chk_off_X) );
2204 // For some types like interfaces the following loadKlass is from a 1-word
2205 // cache which is mutable so can't use immutable memory. Other
2206 // types load from the super-class display table which is immutable.
2207 Node *kmem = might_be_cache ? memory(p2) : immutable_memory();
2208 Node *nkls = _gvn.transform( new (C, 3) LoadKlassNode( NULL, kmem, p2, _gvn.type(p2)->is_ptr(), TypeKlassPtr::OBJECT_OR_NULL ) );
2209
2210 // Compile speed common case: ARE a subtype and we canNOT fail
2211 if( superklass == nkls )
2212 return top(); // false path is dead; no test needed.
2213
2214 // See if we get an immediate positive hit. Happens roughly 83% of the
2215 // time. Test to see if the value loaded just previously from the subklass
2216 // is exactly the superklass.
2217 Node *cmp1 = _gvn.transform( new (C, 3) CmpPNode( superklass, nkls ) );
2218 Node *bol1 = _gvn.transform( new (C, 2) BoolNode( cmp1, BoolTest::eq ) );
2219 IfNode *iff1 = create_and_xform_if( control(), bol1, PROB_LIKELY(0.83f), COUNT_UNKNOWN );
2220 Node *iftrue1 = _gvn.transform( new (C, 1) IfTrueNode ( iff1 ) );
2221 set_control( _gvn.transform( new (C, 1) IfFalseNode( iff1 ) ) );
2222
2223 // Compile speed common case: Check for being deterministic right now. If
2224 // chk_off is a constant and not equal to cacheoff then we are NOT a
2225 // subklass. In this case we need exactly the 1 test above and we can
2226 // return those results immediately.
2227 if (!might_be_cache) {
2228 Node* not_subtype_ctrl = control();
2779
2780 // create a memory projection as for the normal control path
2781 Node* malloc = _gvn.transform(new (C, 1) ProjNode(allocx, TypeFunc::Memory));
2782 set_memory(malloc, rawidx);
2783
2784 // a normal slow-call doesn't change i_o, but an allocation does
2785 // we create a separate i_o projection for the normal control path
2786 set_i_o(_gvn.transform( new (C, 1) ProjNode(allocx, TypeFunc::I_O, false) ) );
2787 Node* rawoop = _gvn.transform( new (C, 1) ProjNode(allocx, TypeFunc::Parms) );
2788
2789 // put in an initialization barrier
2790 InitializeNode* init = insert_mem_bar_volatile(Op_Initialize, rawidx,
2791 rawoop)->as_Initialize();
2792 assert(alloc->initialization() == init, "2-way macro link must work");
2793 assert(init ->allocation() == alloc, "2-way macro link must work");
2794 if (ReduceFieldZeroing && !raw_mem_only) {
2795 // Extract memory strands which may participate in the new object's
2796 // initialization, and source them from the new InitializeNode.
2797 // This will allow us to observe initializations when they occur,
2798 // and link them properly (as a group) to the InitializeNode.
2799 Node* klass_node = alloc->in(AllocateNode::KlassNode);
2800 assert(init->in(InitializeNode::Memory) == malloc, "");
2801 MergeMemNode* minit_in = MergeMemNode::make(C, malloc);
2802 init->set_req(InitializeNode::Memory, minit_in);
2803 record_for_igvn(minit_in); // fold it up later, if possible
2804 Node* minit_out = memory(rawidx);
2805 assert(minit_out->is_Proj() && minit_out->in(0) == init, "");
2806 if (oop_type->isa_aryptr()) {
2807 const TypePtr* telemref = oop_type->add_offset(Type::OffsetBot);
2808 int elemidx = C->get_alias_index(telemref);
2809 hook_memory_on_init(*this, elemidx, minit_in, minit_out);
2810 } else if (oop_type->isa_instptr()) {
2811 ciInstanceKlass* ik = oop_type->klass()->as_instance_klass();
2812 for (int i = 0, len = ik->nof_nonstatic_fields(); i < len; i++) {
2813 ciField* field = ik->nonstatic_field_at(i);
2814 if (field->offset() >= TrackedInitializationLimit)
2815 continue; // do not bother to track really large numbers of fields
2816 // Find (or create) the alias category for this field:
2817 int fieldidx = C->alias_type(field)->index();
2818 hook_memory_on_init(*this, fieldidx, minit_in, minit_out);
2819 }
2820 }
2821 }
2822
2823 // Cast raw oop to the real thing...
2824 Node* javaoop = new (C, 2) CheckCastPPNode(control(), rawoop, oop_type);
2825 javaoop = _gvn.transform(javaoop);
2826 C->set_recent_alloc(control(), javaoop);
2827 assert(just_allocated_object(control()) == javaoop, "just allocated");
2828
2829 #ifdef ASSERT
2830 { // Verify that the AllocateNode::Ideal_foo recognizers work:
2831 Node* kn = alloc->in(AllocateNode::KlassNode);
2832 Node* ln = alloc->in(AllocateNode::ALength);
2833 assert(AllocateNode::Ideal_klass(rawoop, &_gvn) == kn,
2834 "Ideal_klass works");
2835 assert(AllocateNode::Ideal_klass(javaoop, &_gvn) == kn,
2836 "Ideal_klass works");
2837 if (alloc->is_AllocateArray()) {
2838 assert(AllocateArrayNode::Ideal_length(rawoop, &_gvn) == ln,
2839 "Ideal_length works");
2840 assert(AllocateArrayNode::Ideal_length(javaoop, &_gvn) == ln,
2841 "Ideal_length works");
2842 } else {
2843 assert(ln->is_top(), "no length, please");
2844 }
2845 }
2846 #endif //ASSERT
2847
2848 return javaoop;
2849 }
2850
2851 //---------------------------new_instance--------------------------------------
2852 // This routine takes a klass_node which may be constant (for a static type)
2853 // or may be non-constant (for reflective code). It will work equally well
2854 // for either, and the graph will fold nicely if the optimizer later reduces
2855 // the type to a constant.
2856 // The optional arguments are for specialized use by intrinsics:
2857 // - If 'extra_slow_test' if not null is an extra condition for the slow-path.
2858 // - If 'raw_mem_only', do not cast the result to an oop.
2859 // - If 'return_size_val', report the the total object size to the caller.
2860 Node* GraphKit::new_instance(Node* klass_node,
2861 Node* extra_slow_test,
2862 bool raw_mem_only, // affect only raw memory
2863 Node* *return_size_val) {
2900 // This reflective path is used by clone and Unsafe.allocateInstance.
2901 size = ConvI2X(layout_val);
2902
2903 // Clear the low bits to extract layout_helper_size_in_bytes:
2904 assert((int)Klass::_lh_instance_slow_path_bit < BytesPerLong, "clear bit");
2905 Node* mask = MakeConX(~ (intptr_t)right_n_bits(LogBytesPerLong));
2906 size = _gvn.transform( new (C, 3) AndXNode(size, mask) );
2907 }
2908 if (return_size_val != NULL) {
2909 (*return_size_val) = size;
2910 }
2911
2912 // This is a precise notnull oop of the klass.
2913 // (Actually, it need not be precise if this is a reflective allocation.)
2914 // It's what we cast the result to.
2915 const TypeKlassPtr* tklass = _gvn.type(klass_node)->isa_klassptr();
2916 if (!tklass) tklass = TypeKlassPtr::OBJECT;
2917 const TypeOopPtr* oop_type = tklass->as_instance_type();
2918
2919 // Now generate allocation code
2920 AllocateNode* alloc
2921 = new (C, AllocateNode::ParmLimit)
2922 AllocateNode(C, AllocateNode::alloc_type(),
2923 control(), memory(Compile::AliasIdxRaw), i_o(),
2924 size, klass_node,
2925 initial_slow_test);
2926
2927 return set_output_for_allocation(alloc, oop_type, raw_mem_only);
2928 }
2929
2930 //-------------------------------new_array-------------------------------------
2931 // helper for both newarray and anewarray
2932 // The 'length' parameter is (obviously) the length of the array.
2933 // See comments on new_instance for the meaning of the other arguments.
2934 Node* GraphKit::new_array(Node* klass_node, // array klass (maybe variable)
2935 Node* length, // number of array elements
2936 bool raw_mem_only, // affect only raw memory
2937 Node* *return_size_val) {
2938 jint layout_con = Klass::_lh_neutral_value;
2939 Node* layout_val = get_layout_helper(klass_node, layout_con);
2940 int layout_is_con = (layout_val == NULL);
2941
2942 if (!layout_is_con && !StressReflectiveCode &&
2943 !too_many_traps(Deoptimization::Reason_class_check)) {
3034 // Combine header size (plus rounding) and body size. Then round down.
3035 // This computation cannot overflow, because it is used only in two
3036 // places, one where the length is sharply limited, and the other
3037 // after a successful allocation.
3038 Node* abody = lengthx;
3039 if (elem_shift != NULL)
3040 abody = _gvn.transform( new(C, 3) LShiftXNode(lengthx, elem_shift) );
3041 Node* size = _gvn.transform( new(C, 3) AddXNode(headerx, abody) );
3042 if (round_mask != 0) {
3043 Node* mask = MakeConX(~round_mask);
3044 size = _gvn.transform( new(C, 3) AndXNode(size, mask) );
3045 }
3046 // else if round_mask == 0, the size computation is self-rounding
3047
3048 if (return_size_val != NULL) {
3049 // This is the size
3050 (*return_size_val) = size;
3051 }
3052
3053 // Now generate allocation code
3054 // Create the AllocateArrayNode and its result projections
3055 AllocateArrayNode* alloc
3056 = new (C, AllocateArrayNode::ParmLimit)
3057 AllocateArrayNode(C, AllocateArrayNode::alloc_type(),
3058 control(), memory(Compile::AliasIdxRaw), i_o(),
3059 size, klass_node,
3060 initial_slow_test,
3061 length);
3062
3063 // Cast to correct type. Note that the klass_node may be constant or not,
3064 // and in the latter case the actual array type will be inexact also.
3065 // (This happens via a non-constant argument to inline_native_newArray.)
3066 // In any case, the value of klass_node provides the desired array type.
3067 const TypeInt* length_type = _gvn.find_int_type(length);
3068 const TypeInt* narrow_length_type = NULL;
3069 const TypeOopPtr* ary_type = _gvn.type(klass_node)->is_klassptr()->as_instance_type();
3070 if (ary_type->isa_aryptr() && length_type != NULL) {
3071 // Try to get a better type than POS for the size
3072 ary_type = ary_type->is_aryptr()->cast_to_size(length_type);
3073 narrow_length_type = ary_type->is_aryptr()->size();
3074 if (narrow_length_type == length_type)
3075 narrow_length_type = NULL;
3076 }
3077
3078 Node* javaoop = set_output_for_allocation(alloc, ary_type, raw_mem_only);
3079
3080 // Cast length on remaining path to be positive:
3081 if (narrow_length_type != NULL) {
3082 Node* ccast = new (C, 2) CastIINode(length, narrow_length_type);
3083 ccast->set_req(0, control());
3084 _gvn.set_type_bottom(ccast);
3085 record_for_igvn(ccast);
3086 if (map()->find_edge(length) >= 0) {
3087 replace_in_map(length, ccast);
3088 }
3089 }
3090
3091 return javaoop;
3092 }
3093
3094 // The following "Ideal_foo" functions are placed here because they recognize
3095 // the graph shapes created by the functions immediately above.
3096
3097 //---------------------------Ideal_allocation----------------------------------
3098 // Given an oop pointer or raw pointer, see if it feeds from an AllocateNode.
3099 AllocateNode* AllocateNode::Ideal_allocation(Node* ptr, PhaseTransform* phase) {
3100 if (ptr == NULL) { // reduce dumb test in callers
3101 return NULL;
3102 }
3103 if (ptr->is_CheckCastPP()) { // strip a raw-to-oop cast
3104 ptr = ptr->in(1);
3105 if (ptr == NULL) return NULL;
3106 }
3130 if (alloc->is_Allocate()) {
3131 return alloc->as_Allocate();
3132 }
3133 }
3134 return NULL;
3135 }
3136
3137 // Trace Allocate -> Proj[Parm] -> Initialize
3138 InitializeNode* AllocateNode::initialization() {
3139 ProjNode* rawoop = proj_out(AllocateNode::RawAddress);
3140 if (rawoop == NULL) return NULL;
3141 for (DUIterator_Fast imax, i = rawoop->fast_outs(imax); i < imax; i++) {
3142 Node* init = rawoop->fast_out(i);
3143 if (init->is_Initialize()) {
3144 assert(init->as_Initialize()->allocation() == this, "2-way link");
3145 return init->as_Initialize();
3146 }
3147 }
3148 return NULL;
3149 }
|
1 #ifdef USE_PRAGMA_IDENT_SRC
2 #pragma ident "@(#)graphKit.cpp 1.132 07/10/04 14:36:00 JVM"
3 #endif
4 /*
5 * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 *
8 * This code is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 only, as
10 * published by the Free Software Foundation.
11 *
12 * This code is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * version 2 for more details (a copy is included in the LICENSE file that
16 * accompanied this code).
17 *
18 * You should have received a copy of the GNU General Public License version
19 * 2 along with this work; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
24 * have any questions.
25 *
518 ex_obj = env()->ArithmeticException_instance();
519 break;
520 case Deoptimization::Reason_range_check:
521 ex_obj = env()->ArrayIndexOutOfBoundsException_instance();
522 break;
523 case Deoptimization::Reason_class_check:
524 if (java_bc() == Bytecodes::_aastore) {
525 ex_obj = env()->ArrayStoreException_instance();
526 } else {
527 ex_obj = env()->ClassCastException_instance();
528 }
529 break;
530 }
531 if (failing()) { stop(); return; } // exception allocation might fail
532 if (ex_obj != NULL) {
533 // Cheat with a preallocated exception object.
534 if (C->log() != NULL)
535 C->log()->elem("hot_throw preallocated='1' reason='%s'",
536 Deoptimization::trap_reason_name(reason));
537 const TypeInstPtr* ex_con = TypeInstPtr::make(ex_obj);
538 Node* ex_node = _gvn.transform( ConNode::make(C, ex_con) );
539
540 // Clear the detail message of the preallocated exception object.
541 // Weblogic sometimes mutates the detail message of exceptions
542 // using reflection.
543 int offset = java_lang_Throwable::get_detailMessage_offset();
544 const TypePtr* adr_typ = ex_con->add_offset(offset);
545
546 Node *adr = basic_plus_adr(ex_node, ex_node, offset);
547 Node *store = store_oop_to_object(control(), ex_node, adr, adr_typ, null(), ex_con, T_OBJECT);
548
549 add_exception_state(make_exception_state(ex_node));
550 return;
551 }
552 }
553
554 // %%% Maybe add entry to OptoRuntime which directly throws the exc.?
555 // It won't be much cheaper than bailing to the interp., since we'll
556 // have to pass up all the debug-info, and the runtime will have to
557 // create the stack trace.
558
573
574 // "must_throw" prunes the JVM state to include only the stack, if there
575 // are no local exception handlers. This should cut down on register
576 // allocation time and code size, by drastically reducing the number
577 // of in-edges on the call to the uncommon trap.
578
579 uncommon_trap(reason, action, (ciKlass*)NULL, (char*)NULL, must_throw);
580 }
581
582
583 //----------------------------PreserveJVMState---------------------------------
584 PreserveJVMState::PreserveJVMState(GraphKit* kit, bool clone_map) {
585 debug_only(kit->verify_map());
586 _kit = kit;
587 _map = kit->map(); // preserve the map
588 _sp = kit->sp();
589 kit->set_map(clone_map ? kit->clone_map() : NULL);
590 #ifdef ASSERT
591 _bci = kit->bci();
592 Parse* parser = kit->is_Parse();
593 int block = (parser == NULL || parser->block() == NULL) ? -1 : parser->block()->rpo();
594 _block = block;
595 #endif
596 }
597 PreserveJVMState::~PreserveJVMState() {
598 GraphKit* kit = _kit;
599 #ifdef ASSERT
600 assert(kit->bci() == _bci, "bci must not shift");
601 Parse* parser = kit->is_Parse();
602 int block = (parser == NULL || parser->block() == NULL) ? -1 : parser->block()->rpo();
603 assert(block == _block, "block must not shift");
604 #endif
605 kit->set_map(_map);
606 kit->set_sp(_sp);
607 }
608
609
610 //-----------------------------BuildCutout-------------------------------------
611 BuildCutout::BuildCutout(GraphKit* kit, Node* p, float prob, float cnt)
612 : PreserveJVMState(kit)
613 {
614 assert(p->is_Con() || p->is_Bool(), "test must be a bool");
615 SafePointNode* outer_map = _map; // preserved map is caller's
616 SafePointNode* inner_map = kit->map();
617 IfNode* iff = kit->create_and_map_if(outer_map->control(), p, prob, cnt);
618 outer_map->set_control(kit->gvn().transform( new (kit->C, 1) IfTrueNode(iff) ));
619 inner_map->set_control(kit->gvn().transform( new (kit->C, 1) IfFalseNode(iff) ));
620 }
621 BuildCutout::~BuildCutout() {
622 GraphKit* kit = _kit;
843 } else if (can_prune_locals && stack_slots_not_pruned != 0) {
844 // Divide stack into {S0,...,S1}, where S0 is set to top.
845 uint s1 = stack_slots_not_pruned;
846 stack_slots_not_pruned = 0; // for next iteration
847 if (s1 > l) s1 = l;
848 uint s0 = l - s1;
849 p += s0; // skip the tops preinstalled by add_req_batch
850 for (j = s0; j < l; j++)
851 call->set_req(p++, in_map->in(k+j));
852 } else {
853 p += l; // already set to top above by add_req_batch
854 }
855
856 // Add the Monitors
857 k = in_jvms->monoff();
858 l = in_jvms->mon_size();
859 out_jvms->set_monoff(p);
860 for (j = 0; j < l; j++)
861 call->set_req(p++, in_map->in(k+j));
862
863 // Copy any scalar object fields.
864 k = in_jvms->scloff();
865 l = in_jvms->scl_size();
866 out_jvms->set_scloff(p);
867 for (j = 0; j < l; j++)
868 call->set_req(p++, in_map->in(k+j));
869
870 // Finish the new jvms.
871 out_jvms->set_endoff(p);
872
873 assert(out_jvms->endoff() == debug_end, "fill ptr must match");
874 assert(out_jvms->depth() == in_jvms->depth(), "depth must match");
875 assert(out_jvms->loc_size() == in_jvms->loc_size(), "size must match");
876 assert(out_jvms->mon_size() == in_jvms->mon_size(), "size must match");
877 assert(out_jvms->scl_size() == in_jvms->scl_size(), "size must match");
878 assert(out_jvms->debug_size() == in_jvms->debug_size(), "size must match");
879
880 // Update the two tail pointers in parallel.
881 out_jvms = out_jvms->caller();
882 in_jvms = in_jvms->caller();
883 }
884
885 assert(debug_ptr == non_debug_edges, "debug info must fit exactly");
886
887 // Test the correctness of JVMState::debug_xxx accessors:
888 assert(call->jvms()->debug_start() == non_debug_edges, "");
889 assert(call->jvms()->debug_end() == call->req(), "");
890 assert(call->jvms()->debug_depth() == call->req() - non_debug_edges, "");
891 }
892
893 bool GraphKit::compute_stack_effects(int& inputs, int& depth) {
894 Bytecodes::Code code = java_bc();
895 if (code == Bytecodes::_wide) {
896 code = method()->java_code_at_bci(bci() + 1);
897 }
1029 if (offset_con != Type::OffsetBot) {
1030 return longcon((long) offset_con);
1031 }
1032 return _gvn.transform( new (C, 2) ConvI2LNode(offset));
1033 }
1034 Node* GraphKit::ConvL2I(Node* offset) {
1035 // short-circuit a common case
1036 jlong offset_con = find_long_con(offset, (jlong)Type::OffsetBot);
1037 if (offset_con != (jlong)Type::OffsetBot) {
1038 return intcon((int) offset_con);
1039 }
1040 return _gvn.transform( new (C, 2) ConvL2INode(offset));
1041 }
1042
1043 //-------------------------load_object_klass-----------------------------------
1044 Node* GraphKit::load_object_klass(Node* obj) {
1045 // Special-case a fresh allocation to avoid building nodes:
1046 Node* akls = AllocateNode::Ideal_klass(obj, &_gvn);
1047 if (akls != NULL) return akls;
1048 Node* k_adr = basic_plus_adr(obj, oopDesc::klass_offset_in_bytes());
1049 return _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), k_adr, TypeInstPtr::KLASS) );
1050 }
1051
1052 //-------------------------load_array_length-----------------------------------
1053 Node* GraphKit::load_array_length(Node* array) {
1054 // Special-case a fresh allocation to avoid building nodes:
1055 AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(array, &_gvn);
1056 Node *alen;
1057 if (alloc == NULL) {
1058 Node *r_adr = basic_plus_adr(array, arrayOopDesc::length_offset_in_bytes());
1059 alen = _gvn.transform( new (C, 3) LoadRangeNode(0, immutable_memory(), r_adr, TypeInt::POS));
1060 } else {
1061 alen = alloc->Ideal_length();
1062 Node* ccast = alloc->make_ideal_length(_gvn.type(array)->is_aryptr(), &_gvn);
1063 if (ccast != alen) {
1064 alen = _gvn.transform(ccast);
1065 }
1066 }
1067 return alen;
1068 }
1069
1070 //------------------------------do_null_check----------------------------------
1071 // Helper function to do a NULL pointer check. Returned value is
1072 // the incoming address with NULL casted away. You are allowed to use the
1073 // not-null value only if you are control dependent on the test.
1074 extern int explicit_null_checks_inserted,
1075 explicit_null_checks_elided;
1076 Node* GraphKit::null_check_common(Node* value, BasicType type,
1077 // optional arguments for variations:
1078 bool assert_null,
1079 Node* *null_control) {
1080 assert(!assert_null || null_control == NULL, "not both at once");
1081 if (stopped()) return top();
1082 if (!GenerateCompilerNullChecks && !assert_null && null_control == NULL) {
1083 // For some performance testing, we may wish to suppress null checking.
1084 value = cast_not_null(value); // Make it appear to be non-null (4962416).
1085 return value;
1086 }
1087 explicit_null_checks_inserted++;
1175 explicit_null_checks_elided++;
1176 return res;
1177 }
1178 cfg = IfNode::up_one_dom(cfg, /*linear_only=*/ true);
1179 if (cfg == NULL) break; // Quit at region nodes
1180 depth++;
1181 }
1182 }
1183
1184 //-----------
1185 // Branch to failure if null
1186 float ok_prob = PROB_MAX; // a priori estimate: nulls never happen
1187 Deoptimization::DeoptReason reason;
1188 if (assert_null)
1189 reason = Deoptimization::Reason_null_assert;
1190 else if (type == T_OBJECT)
1191 reason = Deoptimization::Reason_null_check;
1192 else
1193 reason = Deoptimization::Reason_div0_check;
1194
1195 // %%% Since Reason_unhandled is not recorded on a per-bytecode basis,
1196 // ciMethodData::has_trap_at will return a conservative -1 if any
1197 // must-be-null assertion has failed. This could cause performance
1198 // problems for a method after its first do_null_assert failure.
1199 // Consider using 'Reason_class_check' instead?
1200
1201 // To cause an implicit null check, we set the not-null probability
1202 // to the maximum (PROB_MAX). For an explicit check the probablity
1203 // is set to a smaller value.
1204 if (null_control != NULL || too_many_traps(reason)) {
1205 // probability is less likely
1206 ok_prob = PROB_LIKELY_MAG(3);
1207 } else if (!assert_null &&
1208 (ImplicitNullCheckThreshold > 0) &&
1209 method() != NULL &&
1210 (method()->method_data()->trap_count(reason)
1211 >= (uint)ImplicitNullCheckThreshold)) {
1212 ok_prob = PROB_LIKELY_MAG(3);
1213 }
1214
1215 if (null_control != NULL) {
1216 IfNode* iff = create_and_map_if(control(), tst, ok_prob, COUNT_UNKNOWN);
1217 Node* null_true = _gvn.transform( new (C, 1) IfFalseNode(iff));
1218 set_control( _gvn.transform( new (C, 1) IfTrueNode(iff)));
1219 if (null_true == top())
1220 explicit_null_checks_elided++;
1221 (*null_control) = null_true;
1222 } else {
1223 BuildCutout unless(this, tst, ok_prob);
1224 // Check for optimizer eliding test at parse time
1225 if (stopped()) {
1226 // Failure not possible; do not bother making uncommon trap.
1227 explicit_null_checks_elided++;
1228 } else if (assert_null) {
1229 uncommon_trap(reason,
1230 Deoptimization::Action_make_not_entrant,
1231 NULL, "assert_null");
1232 } else {
1233 replace_in_map(value, zerocon(type));
1234 builtin_throw(reason);
1235 }
1236 }
1237
1238 // Must throw exception, fall-thru not possible?
1239 if (stopped()) {
1240 return top(); // No result
1241 }
1242
1243 if (assert_null) {
1244 // Cast obj to null on this path.
1245 replace_in_map(value, zerocon(type));
1246 return zerocon(type);
1247 }
1248
1249 // Cast obj to not-null on this path, if there is no null_control.
1250 // (If there is a null_control, a non-null value may come back to haunt us.)
1251 if (type == T_OBJECT) {
1252 Node* cast = cast_not_null(value, false);
1253 if (null_control == NULL || (*null_control) == top())
1330 //=============================================================================
1331 //
1332 // parser factory methods for MemNodes
1333 //
1334 // These are layered on top of the factory methods in LoadNode and StoreNode,
1335 // and integrate with the parser's memory state and _gvn engine.
1336 //
1337
1338 // factory methods in "int adr_idx"
1339 Node* GraphKit::make_load(Node* ctl, Node* adr, const Type* t, BasicType bt,
1340 int adr_idx,
1341 bool require_atomic_access) {
1342 assert(adr_idx != Compile::AliasIdxTop, "use other make_load factory" );
1343 const TypePtr* adr_type = NULL; // debug-mode-only argument
1344 debug_only(adr_type = C->get_adr_type(adr_idx));
1345 Node* mem = memory(adr_idx);
1346 Node* ld;
1347 if (require_atomic_access && bt == T_LONG) {
1348 ld = LoadLNode::make_atomic(C, ctl, mem, adr, adr_type, t);
1349 } else {
1350 ld = LoadNode::make(_gvn, ctl, mem, adr, adr_type, t, bt);
1351 }
1352 return _gvn.transform(ld);
1353 }
1354
1355 Node* GraphKit::store_to_memory(Node* ctl, Node* adr, Node *val, BasicType bt,
1356 int adr_idx,
1357 bool require_atomic_access) {
1358 assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory" );
1359 const TypePtr* adr_type = NULL;
1360 debug_only(adr_type = C->get_adr_type(adr_idx));
1361 Node *mem = memory(adr_idx);
1362 Node* st;
1363 if (require_atomic_access && bt == T_LONG) {
1364 st = StoreLNode::make_atomic(C, ctl, mem, adr, adr_type, val);
1365 } else {
1366 st = StoreNode::make(_gvn, ctl, mem, adr, adr_type, val, bt);
1367 }
1368 st = _gvn.transform(st);
1369 set_memory(st, adr_idx);
1370 // Back-to-back stores can only remove intermediate store with DU info
1371 // so push on worklist for optimizer.
1372 if (mem->req() > MemNode::Address && adr == mem->in(MemNode::Address))
1373 record_for_igvn(st);
1374
1375 return st;
1376 }
1377
1378 void GraphKit::pre_barrier(Node* ctl,
1379 Node* obj,
1380 Node* adr,
1381 uint adr_idx,
1382 Node *val,
1383 const Type* val_type,
1384 BasicType bt) {
1385 BarrierSet* bs = Universe::heap()->barrier_set();
1386 set_control(ctl);
1387 switch (bs->kind()) {
1388 case BarrierSet::G1SATBCT:
1389 case BarrierSet::G1SATBCTLogging:
1390 g1_write_barrier_pre(obj, adr, adr_idx, val, val_type, bt);
1391 break;
1392
1393 case BarrierSet::CardTableModRef:
1394 case BarrierSet::CardTableExtension:
1395 case BarrierSet::ModRef:
1396 break;
1397
1398 case BarrierSet::Other:
1399 default :
1400 ShouldNotReachHere();
1401
1402 }
1403 }
1404
1405 void GraphKit::post_barrier(Node* ctl,
1406 Node* store,
1407 Node* obj,
1408 Node* adr,
1409 uint adr_idx,
1410 Node *val,
1411 BasicType bt,
1412 bool use_precise) {
1413 BarrierSet* bs = Universe::heap()->barrier_set();
1414 set_control(ctl);
1415 switch (bs->kind()) {
1416 case BarrierSet::G1SATBCT:
1417 case BarrierSet::G1SATBCTLogging:
1418 g1_write_barrier_post(store, obj, adr, adr_idx, val, bt, use_precise);
1419 break;
1420
1421 case BarrierSet::CardTableModRef:
1422 case BarrierSet::CardTableExtension:
1423 write_barrier_post(store, obj, adr, val, use_precise);
1424 break;
1425
1426 case BarrierSet::ModRef:
1427 break;
1428
1429 case BarrierSet::Other:
1430 default :
1431 ShouldNotReachHere();
1432
1433 }
1434 }
1435
1436 Node* GraphKit::store_oop_to_object(Node* ctl,
1437 Node* obj,
1438 Node* adr,
1439 const TypePtr* adr_type,
1465
1466 Node* GraphKit::store_oop_to_unknown(Node* ctl,
1467 Node* obj,
1468 Node* adr,
1469 const TypePtr* adr_type,
1470 Node *val,
1471 const Type* val_type,
1472 BasicType bt) {
1473 uint adr_idx = C->get_alias_index(adr_type);
1474 Node* store;
1475 pre_barrier(ctl, obj, adr, adr_idx, val, val_type, bt);
1476 store = store_to_memory(control(), adr, val, bt, adr_idx);
1477 post_barrier(control(), store, obj, adr, adr_idx, val, bt, true);
1478 return store;
1479 }
1480
1481
1482 //-------------------------array_element_address-------------------------
1483 Node* GraphKit::array_element_address(Node* ary, Node* idx, BasicType elembt,
1484 const TypeInt* sizetype) {
1485 uint shift = exact_log2(type2aelembytes(elembt));
1486 uint header = arrayOopDesc::base_offset_in_bytes(elembt);
1487
1488 // short-circuit a common case (saves lots of confusing waste motion)
1489 jint idx_con = find_int_con(idx, -1);
1490 if (idx_con >= 0) {
1491 intptr_t offset = header + ((intptr_t)idx_con << shift);
1492 return basic_plus_adr(ary, offset);
1493 }
1494
1495 // must be correct type for alignment purposes
1496 Node* base = basic_plus_adr(ary, header);
1497 #ifdef _LP64
1498 // The scaled index operand to AddP must be a clean 64-bit value.
1499 // Java allows a 32-bit int to be incremented to a negative
1500 // value, which appears in a 64-bit register as a large
1501 // positive number. Using that large positive number as an
1502 // operand in pointer arithmetic has bad consequences.
1503 // On the other hand, 32-bit overflow is rare, and the possibility
1504 // can often be excluded, if we annotate the ConvI2L node with
1505 // a type assertion that its value is known to be a small positive
1970 // Code is structured as a series of driver functions all called 'do_XXX' that
1971 // call a set of helper functions. Helper functions first, then drivers.
1972
1973 //------------------------------null_check_oop---------------------------------
1974 // Null check oop. Set null-path control into Region in slot 3.
1975 // Make a cast-not-nullness use the other not-null control. Return cast.
1976 Node* GraphKit::null_check_oop(Node* value, Node* *null_control,
1977 bool never_see_null) {
1978 // Initial NULL check taken path
1979 (*null_control) = top();
1980 Node* cast = null_check_common(value, T_OBJECT, false, null_control);
1981
1982 // Generate uncommon_trap:
1983 if (never_see_null && (*null_control) != top()) {
1984 // If we see an unexpected null at a check-cast we record it and force a
1985 // recompile; the offending check-cast will be compiled to handle NULLs.
1986 // If we see more than one offending BCI, then all checkcasts in the
1987 // method will be compiled to handle NULLs.
1988 PreserveJVMState pjvms(this);
1989 set_control(*null_control);
1990 replace_in_map(value, null());
1991 uncommon_trap(Deoptimization::Reason_null_check,
1992 Deoptimization::Action_make_not_entrant);
1993 (*null_control) = top(); // NULL path is dead
1994 }
1995
1996 // Cast away null-ness on the result
1997 return cast;
1998 }
1999
2000 //------------------------------opt_iff----------------------------------------
2001 // Optimize the fast-check IfNode. Set the fast-path region slot 2.
2002 // Return slow-path control.
2003 Node* GraphKit::opt_iff(Node* region, Node* iff) {
2004 IfNode *opt_iff = _gvn.transform(iff)->as_If();
2005
2006 // Fast path taken; set region slot 2
2007 Node *fast_taken = _gvn.transform( new (C, 1) IfFalseNode(opt_iff) );
2008 region->init_req(2,fast_taken); // Capture fast-control
2009
2010 // Fast path not-taken, i.e. slow path
2221 // will always succeed. We could leave a dependency behind to ensure this.
2222
2223 // First load the super-klass's check-offset
2224 Node *p1 = basic_plus_adr( superklass, superklass, sizeof(oopDesc) + Klass::super_check_offset_offset_in_bytes() );
2225 Node *chk_off = _gvn.transform( new (C, 3) LoadINode( NULL, memory(p1), p1, _gvn.type(p1)->is_ptr() ) );
2226 int cacheoff_con = sizeof(oopDesc) + Klass::secondary_super_cache_offset_in_bytes();
2227 bool might_be_cache = (find_int_con(chk_off, cacheoff_con) == cacheoff_con);
2228
2229 // Load from the sub-klass's super-class display list, or a 1-word cache of
2230 // the secondary superclass list, or a failing value with a sentinel offset
2231 // if the super-klass is an interface or exceptionally deep in the Java
2232 // hierarchy and we have to scan the secondary superclass list the hard way.
2233 // Worst-case type is a little odd: NULL is allowed as a result (usually
2234 // klass loads can never produce a NULL).
2235 Node *chk_off_X = ConvI2X(chk_off);
2236 Node *p2 = _gvn.transform( new (C, 4) AddPNode(subklass,subklass,chk_off_X) );
2237 // For some types like interfaces the following loadKlass is from a 1-word
2238 // cache which is mutable so can't use immutable memory. Other
2239 // types load from the super-class display table which is immutable.
2240 Node *kmem = might_be_cache ? memory(p2) : immutable_memory();
2241 Node *nkls = _gvn.transform( LoadKlassNode::make( _gvn, kmem, p2, _gvn.type(p2)->is_ptr(), TypeKlassPtr::OBJECT_OR_NULL ) );
2242
2243 // Compile speed common case: ARE a subtype and we canNOT fail
2244 if( superklass == nkls )
2245 return top(); // false path is dead; no test needed.
2246
2247 // See if we get an immediate positive hit. Happens roughly 83% of the
2248 // time. Test to see if the value loaded just previously from the subklass
2249 // is exactly the superklass.
2250 Node *cmp1 = _gvn.transform( new (C, 3) CmpPNode( superklass, nkls ) );
2251 Node *bol1 = _gvn.transform( new (C, 2) BoolNode( cmp1, BoolTest::eq ) );
2252 IfNode *iff1 = create_and_xform_if( control(), bol1, PROB_LIKELY(0.83f), COUNT_UNKNOWN );
2253 Node *iftrue1 = _gvn.transform( new (C, 1) IfTrueNode ( iff1 ) );
2254 set_control( _gvn.transform( new (C, 1) IfFalseNode( iff1 ) ) );
2255
2256 // Compile speed common case: Check for being deterministic right now. If
2257 // chk_off is a constant and not equal to cacheoff then we are NOT a
2258 // subklass. In this case we need exactly the 1 test above and we can
2259 // return those results immediately.
2260 if (!might_be_cache) {
2261 Node* not_subtype_ctrl = control();
2812
2813 // create a memory projection as for the normal control path
2814 Node* malloc = _gvn.transform(new (C, 1) ProjNode(allocx, TypeFunc::Memory));
2815 set_memory(malloc, rawidx);
2816
2817 // a normal slow-call doesn't change i_o, but an allocation does
2818 // we create a separate i_o projection for the normal control path
2819 set_i_o(_gvn.transform( new (C, 1) ProjNode(allocx, TypeFunc::I_O, false) ) );
2820 Node* rawoop = _gvn.transform( new (C, 1) ProjNode(allocx, TypeFunc::Parms) );
2821
2822 // put in an initialization barrier
2823 InitializeNode* init = insert_mem_bar_volatile(Op_Initialize, rawidx,
2824 rawoop)->as_Initialize();
2825 assert(alloc->initialization() == init, "2-way macro link must work");
2826 assert(init ->allocation() == alloc, "2-way macro link must work");
2827 if (ReduceFieldZeroing && !raw_mem_only) {
2828 // Extract memory strands which may participate in the new object's
2829 // initialization, and source them from the new InitializeNode.
2830 // This will allow us to observe initializations when they occur,
2831 // and link them properly (as a group) to the InitializeNode.
2832 assert(init->in(InitializeNode::Memory) == malloc, "");
2833 MergeMemNode* minit_in = MergeMemNode::make(C, malloc);
2834 init->set_req(InitializeNode::Memory, minit_in);
2835 record_for_igvn(minit_in); // fold it up later, if possible
2836 Node* minit_out = memory(rawidx);
2837 assert(minit_out->is_Proj() && minit_out->in(0) == init, "");
2838 if (oop_type->isa_aryptr()) {
2839 const TypePtr* telemref = oop_type->add_offset(Type::OffsetBot);
2840 int elemidx = C->get_alias_index(telemref);
2841 hook_memory_on_init(*this, elemidx, minit_in, minit_out);
2842 } else if (oop_type->isa_instptr()) {
2843 ciInstanceKlass* ik = oop_type->klass()->as_instance_klass();
2844 for (int i = 0, len = ik->nof_nonstatic_fields(); i < len; i++) {
2845 ciField* field = ik->nonstatic_field_at(i);
2846 if (field->offset() >= TrackedInitializationLimit * HeapWordSize)
2847 continue; // do not bother to track really large numbers of fields
2848 // Find (or create) the alias category for this field:
2849 int fieldidx = C->alias_type(field)->index();
2850 hook_memory_on_init(*this, fieldidx, minit_in, minit_out);
2851 }
2852 }
2853 }
2854
2855 // Cast raw oop to the real thing...
2856 Node* javaoop = new (C, 2) CheckCastPPNode(control(), rawoop, oop_type);
2857 javaoop = _gvn.transform(javaoop);
2858 C->set_recent_alloc(control(), javaoop);
2859 assert(just_allocated_object(control()) == javaoop, "just allocated");
2860
2861 #ifdef ASSERT
2862 { // Verify that the AllocateNode::Ideal_allocation recognizers work:
2863 assert(AllocateNode::Ideal_allocation(rawoop, &_gvn) == alloc,
2864 "Ideal_allocation works");
2865 assert(AllocateNode::Ideal_allocation(javaoop, &_gvn) == alloc,
2866 "Ideal_allocation works");
2867 if (alloc->is_AllocateArray()) {
2868 assert(AllocateArrayNode::Ideal_array_allocation(rawoop, &_gvn) == alloc->as_AllocateArray(),
2869 "Ideal_allocation works");
2870 assert(AllocateArrayNode::Ideal_array_allocation(javaoop, &_gvn) == alloc->as_AllocateArray(),
2871 "Ideal_allocation works");
2872 } else {
2873 assert(alloc->in(AllocateNode::ALength)->is_top(), "no length, please");
2874 }
2875 }
2876 #endif //ASSERT
2877
2878 return javaoop;
2879 }
2880
2881 //---------------------------new_instance--------------------------------------
2882 // This routine takes a klass_node which may be constant (for a static type)
2883 // or may be non-constant (for reflective code). It will work equally well
2884 // for either, and the graph will fold nicely if the optimizer later reduces
2885 // the type to a constant.
2886 // The optional arguments are for specialized use by intrinsics:
2887 // - If 'extra_slow_test' if not null is an extra condition for the slow-path.
2888 // - If 'raw_mem_only', do not cast the result to an oop.
2889 // - If 'return_size_val', report the the total object size to the caller.
2890 Node* GraphKit::new_instance(Node* klass_node,
2891 Node* extra_slow_test,
2892 bool raw_mem_only, // affect only raw memory
2893 Node* *return_size_val) {
2930 // This reflective path is used by clone and Unsafe.allocateInstance.
2931 size = ConvI2X(layout_val);
2932
2933 // Clear the low bits to extract layout_helper_size_in_bytes:
2934 assert((int)Klass::_lh_instance_slow_path_bit < BytesPerLong, "clear bit");
2935 Node* mask = MakeConX(~ (intptr_t)right_n_bits(LogBytesPerLong));
2936 size = _gvn.transform( new (C, 3) AndXNode(size, mask) );
2937 }
2938 if (return_size_val != NULL) {
2939 (*return_size_val) = size;
2940 }
2941
2942 // This is a precise notnull oop of the klass.
2943 // (Actually, it need not be precise if this is a reflective allocation.)
2944 // It's what we cast the result to.
2945 const TypeKlassPtr* tklass = _gvn.type(klass_node)->isa_klassptr();
2946 if (!tklass) tklass = TypeKlassPtr::OBJECT;
2947 const TypeOopPtr* oop_type = tklass->as_instance_type();
2948
2949 // Now generate allocation code
2950
2951 // With escape analysis, the entire memory state is needed to be able to
2952 // eliminate the allocation. If the allocations cannot be eliminated, this
2953 // will be optimized to the raw slice when the allocation is expanded.
2954 Node *mem;
2955 if (C->do_escape_analysis()) {
2956 mem = reset_memory();
2957 set_all_memory(mem);
2958 } else {
2959 mem = memory(Compile::AliasIdxRaw);
2960 }
2961
2962 AllocateNode* alloc
2963 = new (C, AllocateNode::ParmLimit)
2964 AllocateNode(C, AllocateNode::alloc_type(),
2965 control(), mem, i_o(),
2966 size, klass_node,
2967 initial_slow_test);
2968
2969 return set_output_for_allocation(alloc, oop_type, raw_mem_only);
2970 }
2971
2972 //-------------------------------new_array-------------------------------------
2973 // helper for both newarray and anewarray
2974 // The 'length' parameter is (obviously) the length of the array.
2975 // See comments on new_instance for the meaning of the other arguments.
2976 Node* GraphKit::new_array(Node* klass_node, // array klass (maybe variable)
2977 Node* length, // number of array elements
2978 bool raw_mem_only, // affect only raw memory
2979 Node* *return_size_val) {
2980 jint layout_con = Klass::_lh_neutral_value;
2981 Node* layout_val = get_layout_helper(klass_node, layout_con);
2982 int layout_is_con = (layout_val == NULL);
2983
2984 if (!layout_is_con && !StressReflectiveCode &&
2985 !too_many_traps(Deoptimization::Reason_class_check)) {
3076 // Combine header size (plus rounding) and body size. Then round down.
3077 // This computation cannot overflow, because it is used only in two
3078 // places, one where the length is sharply limited, and the other
3079 // after a successful allocation.
3080 Node* abody = lengthx;
3081 if (elem_shift != NULL)
3082 abody = _gvn.transform( new(C, 3) LShiftXNode(lengthx, elem_shift) );
3083 Node* size = _gvn.transform( new(C, 3) AddXNode(headerx, abody) );
3084 if (round_mask != 0) {
3085 Node* mask = MakeConX(~round_mask);
3086 size = _gvn.transform( new(C, 3) AndXNode(size, mask) );
3087 }
3088 // else if round_mask == 0, the size computation is self-rounding
3089
3090 if (return_size_val != NULL) {
3091 // This is the size
3092 (*return_size_val) = size;
3093 }
3094
3095 // Now generate allocation code
3096
3097 // With escape analysis, the entire memory state is needed to be able to
3098 // eliminate the allocation. If the allocations cannot be eliminated, this
3099 // will be optimized to the raw slice when the allocation is expanded.
3100 Node *mem;
3101 if (C->do_escape_analysis()) {
3102 mem = reset_memory();
3103 set_all_memory(mem);
3104 } else {
3105 mem = memory(Compile::AliasIdxRaw);
3106 }
3107
3108 // Create the AllocateArrayNode and its result projections
3109 AllocateArrayNode* alloc
3110 = new (C, AllocateArrayNode::ParmLimit)
3111 AllocateArrayNode(C, AllocateArrayNode::alloc_type(),
3112 control(), mem, i_o(),
3113 size, klass_node,
3114 initial_slow_test,
3115 length);
3116
3117 // Cast to correct type. Note that the klass_node may be constant or not,
3118 // and in the latter case the actual array type will be inexact also.
3119 // (This happens via a non-constant argument to inline_native_newArray.)
3120 // In any case, the value of klass_node provides the desired array type.
3121 const TypeInt* length_type = _gvn.find_int_type(length);
3122 const TypeOopPtr* ary_type = _gvn.type(klass_node)->is_klassptr()->as_instance_type();
3123 if (ary_type->isa_aryptr() && length_type != NULL) {
3124 // Try to get a better type than POS for the size
3125 ary_type = ary_type->is_aryptr()->cast_to_size(length_type);
3126 }
3127
3128 Node* javaoop = set_output_for_allocation(alloc, ary_type, raw_mem_only);
3129
3130 // Cast length on remaining path to be as narrow as possible
3131 if (map()->find_edge(length) >= 0) {
3132 Node* ccast = alloc->make_ideal_length(ary_type, &_gvn);
3133 if (ccast != length) {
3134 _gvn.set_type_bottom(ccast);
3135 record_for_igvn(ccast);
3136 replace_in_map(length, ccast);
3137 }
3138 }
3139
3140 return javaoop;
3141 }
3142
3143 // The following "Ideal_foo" functions are placed here because they recognize
3144 // the graph shapes created by the functions immediately above.
3145
3146 //---------------------------Ideal_allocation----------------------------------
3147 // Given an oop pointer or raw pointer, see if it feeds from an AllocateNode.
3148 AllocateNode* AllocateNode::Ideal_allocation(Node* ptr, PhaseTransform* phase) {
3149 if (ptr == NULL) { // reduce dumb test in callers
3150 return NULL;
3151 }
3152 if (ptr->is_CheckCastPP()) { // strip a raw-to-oop cast
3153 ptr = ptr->in(1);
3154 if (ptr == NULL) return NULL;
3155 }
3179 if (alloc->is_Allocate()) {
3180 return alloc->as_Allocate();
3181 }
3182 }
3183 return NULL;
3184 }
3185
3186 // Trace Allocate -> Proj[Parm] -> Initialize
3187 InitializeNode* AllocateNode::initialization() {
3188 ProjNode* rawoop = proj_out(AllocateNode::RawAddress);
3189 if (rawoop == NULL) return NULL;
3190 for (DUIterator_Fast imax, i = rawoop->fast_outs(imax); i < imax; i++) {
3191 Node* init = rawoop->fast_out(i);
3192 if (init->is_Initialize()) {
3193 assert(init->as_Initialize()->allocation() == this, "2-way link");
3194 return init->as_Initialize();
3195 }
3196 }
3197 return NULL;
3198 }
3199
3200 void GraphKit::g1_write_barrier_pre(Node* obj,
3201 Node* adr,
3202 uint alias_idx,
3203 Node* val,
3204 const Type* val_type,
3205 BasicType bt) {
3206 IdealKit ideal(gvn(), control(), merged_memory(), true);
3207 #define __ ideal.
3208 __ declares_done();
3209
3210 Node* thread = __ thread();
3211
3212 Node* no_ctrl = NULL;
3213 Node* no_base = __ top();
3214 Node* zero = __ ConI(0);
3215
3216 float likely = PROB_LIKELY(0.999);
3217 float unlikely = PROB_UNLIKELY(0.999);
3218
3219 BasicType active_type = in_bytes(PtrQueue::byte_width_of_active()) == 4 ? T_INT : T_BYTE;
3220 assert(in_bytes(PtrQueue::byte_width_of_active()) == 4 || in_bytes(PtrQueue::byte_width_of_active()) == 1, "flag width");
3221
3222 // Offsets into the thread
3223 const int marking_offset = in_bytes(JavaThread::satb_mark_queue_offset() + // 648
3224 PtrQueue::byte_offset_of_active());
3225 const int index_offset = in_bytes(JavaThread::satb_mark_queue_offset() + // 656
3226 PtrQueue::byte_offset_of_index());
3227 const int buffer_offset = in_bytes(JavaThread::satb_mark_queue_offset() + // 652
3228 PtrQueue::byte_offset_of_buf());
3229 // Now the actual pointers into the thread
3230
3231 // set_control( ctl);
3232
3233 Node* marking_adr = __ AddP(no_base, thread, __ ConX(marking_offset));
3234 Node* buffer_adr = __ AddP(no_base, thread, __ ConX(buffer_offset));
3235 Node* index_adr = __ AddP(no_base, thread, __ ConX(index_offset));
3236
3237 // Now some of the values
3238
3239 Node* marking = __ load(__ ctrl(), marking_adr, TypeInt::INT, active_type, Compile::AliasIdxRaw);
3240
3241 // if (!marking)
3242 __ if_then(marking, BoolTest::ne, zero); {
3243 Node* index = __ load(__ ctrl(), index_adr, TypeInt::INT, T_INT, Compile::AliasIdxRaw);
3244
3245 const Type* t1 = adr->bottom_type();
3246 const Type* t2 = val->bottom_type();
3247
3248 Node* orig = __ load(no_ctrl, adr, val_type, bt, alias_idx);
3249 // if (orig != NULL)
3250 __ if_then(orig, BoolTest::ne, null()); {
3251 Node* buffer = __ load(__ ctrl(), buffer_adr, TypeRawPtr::NOTNULL, T_ADDRESS, Compile::AliasIdxRaw);
3252
3253 // load original value
3254 // alias_idx correct??
3255
3256 // is the queue for this thread full?
3257 __ if_then(index, BoolTest::ne, zero, likely); {
3258
3259 // decrement the index
3260 Node* next_index = __ SubI(index, __ ConI(sizeof(intptr_t)));
3261 Node* next_indexX = next_index;
3262 #ifdef _LP64
3263 // We could refine the type for what it's worth
3264 // const TypeLong* lidxtype = TypeLong::make(CONST64(0), get_size_from_queue);
3265 next_indexX = _gvn.transform( new (C, 2) ConvI2LNode(next_index, TypeLong::make(0, max_jlong, Type::WidenMax)) );
3266 #endif // _LP64
3267
3268 // Now get the buffer location we will log the original value into and store it
3269
3270 Node *log_addr = __ AddP(no_base, buffer, next_indexX);
3271 // __ store(__ ctrl(), log_addr, orig, T_OBJECT, C->get_alias_index(TypeOopPtr::BOTTOM));
3272 __ store(__ ctrl(), log_addr, orig, T_OBJECT, Compile::AliasIdxRaw);
3273
3274
3275 // update the index
3276 // __ store(__ ctrl(), index_adr, next_index, T_INT, Compile::AliasIdxRaw);
3277 // This is a hack to force this store to occur before the oop store that is coming up
3278 __ store(__ ctrl(), index_adr, next_index, T_INT, C->get_alias_index(TypeOopPtr::BOTTOM));
3279
3280 } __ else_(); {
3281
3282 // logging buffer is full, call the runtime
3283 const TypeFunc *tf = OptoRuntime::g1_wb_pre_Type();
3284 // __ make_leaf_call(tf, OptoRuntime::g1_wb_pre_Java(), "g1_wb_pre", orig, thread);
3285 __ make_leaf_call(tf, CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_pre), "g1_wb_pre", orig, thread);
3286 } __ end_if();
3287 } __ end_if();
3288 } __ end_if();
3289
3290 __ drain_delay_transform();
3291 set_control( __ ctrl());
3292 set_all_memory( __ merged_memory());
3293
3294 #undef __
3295 }
3296
3297 //
3298 // Update the card table and add card address to the queue
3299 //
3300 void GraphKit::g1_mark_card(IdealKit* ideal, Node* card_adr, Node* store, Node* index, Node* index_adr, Node* buffer, const TypeFunc* tf) {
3301 #define __ ideal->
3302 Node* zero = __ ConI(0);
3303 Node* no_base = __ top();
3304 BasicType card_bt = T_BYTE;
3305 // Smash zero into card. MUST BE ORDERED WRT TO STORE
3306 __ storeCM(__ ctrl(), card_adr, zero, store, card_bt, Compile::AliasIdxRaw);
3307
3308 // Now do the queue work
3309 __ if_then(index, BoolTest::ne, zero); {
3310
3311 Node* next_index = __ SubI(index, __ ConI(sizeof(intptr_t)));
3312 Node* next_indexX = next_index;
3313 #ifdef _LP64
3314 // We could refine the type for what it's worth
3315 // const TypeLong* lidxtype = TypeLong::make(CONST64(0), get_size_from_queue);
3316 next_indexX = _gvn.transform( new (C, 2) ConvI2LNode(next_index, TypeLong::make(0, max_jlong, Type::WidenMax)) );
3317 #endif // _LP64
3318 Node* log_addr = __ AddP(no_base, buffer, next_indexX);
3319
3320 __ store(__ ctrl(), log_addr, card_adr, T_ADDRESS, Compile::AliasIdxRaw);
3321 __ store(__ ctrl(), index_adr, next_index, T_INT, Compile::AliasIdxRaw);
3322
3323 } __ else_(); {
3324 __ make_leaf_call(tf, CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_post), "g1_wb_post", card_adr, __ thread());
3325 } __ end_if();
3326 #undef __
3327 }
3328
3329 void GraphKit::g1_write_barrier_post(Node* store,
3330 Node* obj,
3331 Node* adr,
3332 uint alias_idx,
3333 Node* val,
3334 BasicType bt,
3335 bool use_precise) {
3336 // If we are writing a NULL then we need no post barrier
3337
3338 if (val != NULL && val->is_Con() && val->bottom_type() == TypePtr::NULL_PTR) {
3339 // Must be NULL
3340 const Type* t = val->bottom_type();
3341 assert(t == Type::TOP || t == TypePtr::NULL_PTR, "must be NULL");
3342 // No post barrier if writing NULLx
3343 return;
3344 }
3345
3346 if (!use_precise) {
3347 // All card marks for a (non-array) instance are in one place:
3348 adr = obj;
3349 }
3350 // (Else it's an array (or unknown), and we want more precise card marks.)
3351 assert(adr != NULL, "");
3352
3353 IdealKit ideal(gvn(), control(), merged_memory(), true);
3354 #define __ ideal.
3355 __ declares_done();
3356
3357 Node* thread = __ thread();
3358
3359 Node* no_ctrl = NULL;
3360 Node* no_base = __ top();
3361 float likely = PROB_LIKELY(0.999);
3362 float unlikely = PROB_UNLIKELY(0.999);
3363 Node* zero = __ ConI(0);
3364 Node* zeroX = __ ConX(0);
3365
3366 // Get the alias_index for raw card-mark memory
3367 const TypePtr* card_type = TypeRawPtr::BOTTOM;
3368
3369 const TypeFunc *tf = OptoRuntime::g1_wb_post_Type();
3370
3371 // Get the address of the card table
3372 CardTableModRefBS* ct =
3373 (CardTableModRefBS*)(Universe::heap()->barrier_set());
3374 Node *card_table = __ makecon(TypeRawPtr::make((address)ct->byte_map_base));
3375 // Get base of card map
3376 assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code");
3377
3378
3379 // Offsets into the thread
3380 const int index_offset = in_bytes(JavaThread::dirty_card_queue_offset() +
3381 PtrQueue::byte_offset_of_index());
3382 const int buffer_offset = in_bytes(JavaThread::dirty_card_queue_offset() +
3383 PtrQueue::byte_offset_of_buf());
3384
3385 // Pointers into the thread
3386
3387 Node* buffer_adr = __ AddP(no_base, thread, __ ConX(buffer_offset));
3388 Node* index_adr = __ AddP(no_base, thread, __ ConX(index_offset));
3389
3390 // Now some values
3391
3392 Node* index = __ load(no_ctrl, index_adr, TypeInt::INT, T_INT, Compile::AliasIdxRaw);
3393 Node* buffer = __ load(no_ctrl, buffer_adr, TypeRawPtr::NOTNULL, T_ADDRESS, Compile::AliasIdxRaw);
3394
3395
3396 // Convert the store obj pointer to an int prior to doing math on it
3397 // Use addr not obj gets accurate card marks
3398
3399 // Node* cast = __ CastPX(no_ctrl, adr /* obj */);
3400
3401 // Must use ctrl to prevent "integerized oop" existing across safepoint
3402 Node* cast = __ CastPX(__ ctrl(), ( use_precise ? adr : obj ));
3403
3404 // Divide pointer by card size
3405 Node* card_offset = __ URShiftX( cast, __ ConI(CardTableModRefBS::card_shift) );
3406
3407 // Combine card table base and card offset
3408 Node *card_adr = __ AddP(no_base, card_table, card_offset );
3409
3410 // If we know the value being stored does it cross regions?
3411
3412 if (val != NULL) {
3413 // Does the store cause us to cross regions?
3414
3415 // Should be able to do an unsigned compare of region_size instead of
3416 // and extra shift. Do we have an unsigned compare??
3417 // Node* region_size = __ ConI(1 << HeapRegion::LogOfHRGrainBytes);
3418 Node* xor_res = __ URShiftX ( __ XorX( cast, __ CastPX(__ ctrl(), val)), __ ConI(HeapRegion::LogOfHRGrainBytes));
3419
3420 // if (xor_res == 0) same region so skip
3421 __ if_then(xor_res, BoolTest::ne, zeroX); {
3422
3423 // No barrier if we are storing a NULL
3424 __ if_then(val, BoolTest::ne, null(), unlikely); {
3425
3426 // Ok must mark the card if not already dirty
3427
3428 // load the original value of the card
3429 Node* card_val = __ load(__ ctrl(), card_adr, TypeInt::INT, T_BYTE, Compile::AliasIdxRaw);
3430
3431 __ if_then(card_val, BoolTest::ne, zero); {
3432 g1_mark_card(&ideal, card_adr, store, index, index_adr, buffer, tf);
3433 } __ end_if();
3434 } __ end_if();
3435 } __ end_if();
3436 } else {
3437 g1_mark_card(&ideal, card_adr, store, index, index_adr, buffer, tf);
3438 }
3439
3440
3441 __ drain_delay_transform();
3442 set_control( __ ctrl());
3443 set_all_memory( __ merged_memory());
3444 #undef __
3445
3446 }
|