1439 Value receiver; 1440 if (!method()->is_static()) { 1441 receiver = _initial_state->local_at(0); 1442 } else { 1443 receiver = append(new Constant(new ClassConstant(method()->holder()))); 1444 } 1445 append_split(new MonitorExit(receiver, state()->unlock())); 1446 } 1447 1448 append(new Return(x)); 1449 } 1450 1451 1452 void GraphBuilder::access_field(Bytecodes::Code code) { 1453 bool will_link; 1454 ciField* field = stream()->get_field(will_link); 1455 ciInstanceKlass* holder = field->holder(); 1456 BasicType field_type = field->type()->basic_type(); 1457 ValueType* type = as_ValueType(field_type); 1458 // call will_link again to determine if the field is valid. 1459 const bool is_loaded = holder->is_loaded() && 1460 field->will_link(method()->holder(), code); 1461 const bool is_initialized = is_loaded && holder->is_initialized(); 1462 1463 ValueStack* state_before = NULL; 1464 if (!is_initialized || PatchALot) { 1465 // save state before instruction for debug info when 1466 // deoptimization happens during patching 1467 state_before = copy_state_before(); 1468 } 1469 1470 Value obj = NULL; 1471 if (code == Bytecodes::_getstatic || code == Bytecodes::_putstatic) { 1472 // commoning of class constants should only occur if the class is 1473 // fully initialized and resolved in this constant pool. The will_link test 1474 // above essentially checks if this class is resolved in this constant pool 1475 // so, the is_initialized flag should be suffiect. 1476 if (state_before != NULL) { 1477 // build a patching constant 1478 obj = new Constant(new ClassConstant(holder), state_before); 1479 } else { 1480 obj = new Constant(new ClassConstant(holder)); 1481 } 1482 } 1483 1484 1485 const int offset = is_loaded ? field->offset() : -1; 1486 switch (code) { 1487 case Bytecodes::_getstatic: { 1488 // check for compile-time constants, i.e., initialized static final fields 1489 Instruction* constant = NULL; 1490 if (field->is_constant() && !PatchALot) { 1491 ciConstant field_val = field->constant_value(); 1492 BasicType field_type = field_val.basic_type(); 1493 switch (field_type) { 1494 case T_ARRAY: 1495 case T_OBJECT: 1496 if (field_val.as_object()->should_be_constant()) { 1497 constant = new Constant(as_ValueType(field_val)); 1498 } 1499 break; 1500 1501 default: 1502 constant = new Constant(as_ValueType(field_val)); 1503 } 1504 } 1505 if (constant != NULL) { 1506 push(type, append(constant)); 1507 } else { 1508 if (state_before == NULL) { 1509 state_before = copy_state_for_exception(); 1510 } 1511 push(type, append(new LoadField(append(obj), offset, field, true, 1512 state_before, is_loaded, is_initialized))); 1513 } 1514 break; 1515 } 1516 case Bytecodes::_putstatic: 1517 { Value val = pop(type); 1518 if (state_before == NULL) { 1519 state_before = copy_state_for_exception(); 1520 } 1521 append(new StoreField(append(obj), offset, field, val, true, state_before, is_loaded, is_initialized)); 1522 } 1523 break; 1524 case Bytecodes::_getfield : 1525 { 1526 if (state_before == NULL) { 1527 state_before = copy_state_for_exception(); 1528 } 1529 LoadField* load = new LoadField(apop(), offset, field, false, state_before, is_loaded, true); 1530 Value replacement = is_loaded ? _memory->load(load) : load; 1531 if (replacement != load) { 1532 assert(replacement->is_linked() || !replacement->can_be_linked(), "should already by linked"); 1533 push(type, replacement); 1534 } else { 1535 push(type, append(load)); 1536 } 1537 break; 1538 } 1539 1540 case Bytecodes::_putfield : 1541 { Value val = pop(type); 1542 if (state_before == NULL) { 1543 state_before = copy_state_for_exception(); 1544 } 1545 StoreField* store = new StoreField(apop(), offset, field, val, false, state_before, is_loaded, true); 1546 if (is_loaded) store = _memory->store(store); 1547 if (store != NULL) { 1548 append(store); 1549 } 1550 } 1551 break; 1552 default : 1553 ShouldNotReachHere(); 1554 break; 1555 } 1556 } 1557 1558 1559 Dependencies* GraphBuilder::dependency_recorder() const { 1560 assert(DeoptC1, "need debug information"); 1561 return compilation()->dependency_recorder(); 1562 } 1563 1564 1565 void GraphBuilder::invoke(Bytecodes::Code code) { 1566 bool will_link; | 1439 Value receiver; 1440 if (!method()->is_static()) { 1441 receiver = _initial_state->local_at(0); 1442 } else { 1443 receiver = append(new Constant(new ClassConstant(method()->holder()))); 1444 } 1445 append_split(new MonitorExit(receiver, state()->unlock())); 1446 } 1447 1448 append(new Return(x)); 1449 } 1450 1451 1452 void GraphBuilder::access_field(Bytecodes::Code code) { 1453 bool will_link; 1454 ciField* field = stream()->get_field(will_link); 1455 ciInstanceKlass* holder = field->holder(); 1456 BasicType field_type = field->type()->basic_type(); 1457 ValueType* type = as_ValueType(field_type); 1458 // call will_link again to determine if the field is valid. 1459 const bool needs_patching = !holder->is_loaded() || 1460 !field->will_link(method()->holder(), code) || 1461 PatchALot; 1462 1463 ValueStack* state_before = NULL; 1464 if (!holder->is_initialized() || needs_patching) { 1465 // save state before instruction for debug info when 1466 // deoptimization happens during patching 1467 state_before = copy_state_before(); 1468 } 1469 1470 Value obj = NULL; 1471 if (code == Bytecodes::_getstatic || code == Bytecodes::_putstatic) { 1472 if (state_before != NULL) { 1473 // build a patching constant 1474 obj = new Constant(new ClassConstant(holder), state_before); 1475 } else { 1476 obj = new Constant(new ClassConstant(holder)); 1477 } 1478 } 1479 1480 1481 const int offset = !needs_patching ? field->offset() : -1; 1482 switch (code) { 1483 case Bytecodes::_getstatic: { 1484 // check for compile-time constants, i.e., initialized static final fields 1485 Instruction* constant = NULL; 1486 if (field->is_constant() && !PatchALot) { 1487 ciConstant field_val = field->constant_value(); 1488 BasicType field_type = field_val.basic_type(); 1489 switch (field_type) { 1490 case T_ARRAY: 1491 case T_OBJECT: 1492 if (field_val.as_object()->should_be_constant()) { 1493 constant = new Constant(as_ValueType(field_val)); 1494 } 1495 break; 1496 1497 default: 1498 constant = new Constant(as_ValueType(field_val)); 1499 } 1500 } 1501 if (constant != NULL) { 1502 push(type, append(constant)); 1503 } else { 1504 if (state_before == NULL) { 1505 state_before = copy_state_for_exception(); 1506 } 1507 push(type, append(new LoadField(append(obj), offset, field, true, 1508 state_before, needs_patching))); 1509 } 1510 break; 1511 } 1512 case Bytecodes::_putstatic: 1513 { Value val = pop(type); 1514 if (state_before == NULL) { 1515 state_before = copy_state_for_exception(); 1516 } 1517 append(new StoreField(append(obj), offset, field, val, true, state_before, needs_patching)); 1518 } 1519 break; 1520 case Bytecodes::_getfield : 1521 { 1522 if (state_before == NULL) { 1523 state_before = copy_state_for_exception(); 1524 } 1525 LoadField* load = new LoadField(apop(), offset, field, false, state_before, needs_patching); 1526 Value replacement = !needs_patching ? _memory->load(load) : load; 1527 if (replacement != load) { 1528 assert(replacement->is_linked() || !replacement->can_be_linked(), "should already by linked"); 1529 push(type, replacement); 1530 } else { 1531 push(type, append(load)); 1532 } 1533 break; 1534 } 1535 1536 case Bytecodes::_putfield : 1537 { Value val = pop(type); 1538 if (state_before == NULL) { 1539 state_before = copy_state_for_exception(); 1540 } 1541 StoreField* store = new StoreField(apop(), offset, field, val, false, state_before, needs_patching); 1542 if (!needs_patching) store = _memory->store(store); 1543 if (store != NULL) { 1544 append(store); 1545 } 1546 } 1547 break; 1548 default : 1549 ShouldNotReachHere(); 1550 break; 1551 } 1552 } 1553 1554 1555 Dependencies* GraphBuilder::dependency_recorder() const { 1556 assert(DeoptC1, "need debug information"); 1557 return compilation()->dependency_recorder(); 1558 } 1559 1560 1561 void GraphBuilder::invoke(Bytecodes::Code code) { 1562 bool will_link; |