< prev index next >

src/hotspot/share/c1/c1_LIRGenerator.cpp

Print this page


1526       value.load_byte_item();
1527     } else  {
1528       value.load_item();
1529     }
1530   } else {
1531     value.load_for_store(field_type);
1532   }
1533 
1534   set_no_result(x);
1535 
1536 #ifndef PRODUCT
1537   if (PrintNotLoaded && needs_patching) {
1538     tty->print_cr("   ###class not loaded at store_%s bci %d",
1539                   x->is_static() ?  "static" : "field", x->printable_bci());
1540   }
1541 #endif
1542 
1543   if (x->needs_null_check() &&
1544       (needs_patching ||
1545        MacroAssembler::needs_explicit_null_check(x->offset()))) {
1546     if (needs_patching && x->field()->is_q_type()) {
1547       // We are storing a field of type "QT;" into holder class H, but H is not yet
1548       // loaded. (If H had been loaded, then T must also have already been loaded
1549       // due to the "Q" signature, and needs_patching would be false).
1550       assert(!x->field()->holder()->is_loaded(), "must be");
1551       // We don't know the offset of this field. Let's deopt and recompile.
1552       CodeStub* stub = new DeoptimizeStub(new CodeEmitInfo(info),
1553                                           Deoptimization::Reason_unloaded,
1554                                           Deoptimization::Action_make_not_entrant);
1555       __ branch(lir_cond_always, T_ILLEGAL, stub);
1556     } else {
1557       // Emit an explicit null check because the offset is too large.
1558       // If the class is not loaded and the object is NULL, we need to deoptimize to throw a
1559       // NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.
1560       __ null_check(object.result(), new CodeEmitInfo(info), /* deoptimize */ needs_patching);
1561     }
1562   }
1563 
1564   DecoratorSet decorators = IN_HEAP;
1565   if (is_volatile) {
1566     decorators |= MO_SEQ_CST;


1854   decorators |= ACCESS_WRITE;
1855   // Atomic operations are SEQ_CST by default
1856   decorators |= ((decorators & MO_DECORATOR_MASK) != 0) ? MO_SEQ_CST : 0;
1857   LIRAccess access(this, decorators, base, offset, type);
1858   if (access.is_raw()) {
1859     return _barrier_set->BarrierSetC1::atomic_add_at(access, value);
1860   } else {
1861     return _barrier_set->atomic_add_at(access, value);
1862   }
1863 }
1864 
1865 LIR_Opr LIRGenerator::access_resolve(DecoratorSet decorators, LIR_Opr obj) {
1866   // Use stronger ACCESS_WRITE|ACCESS_READ by default.
1867   if ((decorators & (ACCESS_READ | ACCESS_WRITE)) == 0) {
1868     decorators |= ACCESS_READ | ACCESS_WRITE;
1869   }
1870 
1871   return _barrier_set->resolve(this, decorators, obj);
1872 }
1873 
1874 Value LIRGenerator::q_type_load_field_prolog(LoadField* x, CodeEmitInfo* info) {
1875   ciField* field = x->field();
1876   ciInstanceKlass* holder = field->holder();
1877   Value default_value = NULL;
1878 
1879   // Unloaded "QV;" klasses are represented by a ciInstanceKlass
1880   bool field_type_unloaded = field->type()->is_instance_klass() && !field->type()->as_instance_klass()->is_loaded();
1881 
1882   // Check for edge cases (1), (2) and (3) for getstatic and getfield
1883   bool deopt = false;
1884   bool need_default = false;
1885   if (field->is_static()) {
1886       // (1) holder is unloaded -- no problem: it will be loaded by patching, and field offset will be determined.

1887 
1888     if (field_type_unloaded) {
1889       // (2) field type is unloaded -- problem: we don't know what the default value is. Let's deopt.
1890       //                               FIXME: consider getting the default value in patching code.
1891       deopt = true;
1892     } else {
1893       need_default = true;
1894     }
1895 
1896       // (3) field is not flattenable -- we don't care: static fields are never flattened.

1897   } else {
1898     if (!holder->is_loaded()) {
1899       // (1) holder is unloaded -- problem: we needed the field offset back in GraphBuilder::access_field()
1900       //                           FIXME: consider getting field offset in patching code (but only if the field
1901       //                           type was loaded at compilation time).
1902       deopt = true;
1903     } else if (field_type_unloaded) {
1904       // (2) field type is unloaded -- problem: we don't whether it's flattened or not. Let's deopt
1905       deopt = true;
1906     } else if (!field->is_flattened()) {
1907       // (3) field is not flattenable -- need default value in cases of uninitialized field
1908       need_default = true;
1909     }
1910   }
1911 
1912   assert(!(deopt && need_default), "cannot both be true");
1913 
1914   if (deopt) {

1915     assert(x->needs_patching(), "must be");
1916     assert(info != NULL, "must be");
1917     CodeStub* stub = new DeoptimizeStub(new CodeEmitInfo(info),
1918                                         Deoptimization::Reason_unloaded,
1919                                         Deoptimization::Action_make_not_entrant);
1920     __ branch(lir_cond_always, T_ILLEGAL, stub);
1921   } else if (need_default) {
1922     assert(!field_type_unloaded, "must be");
1923     assert(field->type()->is_valuetype(), "must be");
1924     ciValueKlass* value_klass = field->type()->as_value_klass();
1925     assert(value_klass->is_loaded(), "must be");
1926 
1927     if (field->is_static() && holder->is_loaded()) {
1928       ciInstance* mirror = field->holder()->java_mirror();
1929       ciObject* val = mirror->field_value(field).as_object();
1930       if (val->is_null_object()) {
1931         // This is a non-nullable static field, but it's not initialized.
1932         // We need to do a null check, and replace it with the default value.
1933       } else {
1934         // No need to perform null check on this static field


1957     NullCheck* nc = x->explicit_null_check();
1958     if (nc == NULL) {
1959       info = state_for(x);
1960     } else {
1961       info = state_for(nc);
1962     }
1963   }
1964 
1965   LIRItem object(x->obj(), this);
1966 
1967   object.load_item();
1968 
1969 #ifndef PRODUCT
1970   if (PrintNotLoaded && needs_patching) {
1971     tty->print_cr("   ###class not loaded at load_%s bci %d",
1972                   x->is_static() ?  "static" : "field", x->printable_bci());
1973   }
1974 #endif
1975 
1976   Value default_value = NULL;
1977   if (x->field()->is_q_type()) {
1978     default_value = q_type_load_field_prolog(x, info);
1979   }
1980 
1981   bool stress_deopt = StressLoopInvariantCodeMotion && info && info->deoptimize_on_exception();
1982   if (x->needs_null_check() &&
1983       (needs_patching ||
1984        MacroAssembler::needs_explicit_null_check(x->offset()) ||
1985        stress_deopt)) {
1986     LIR_Opr obj = object.result();
1987     if (stress_deopt) {
1988       obj = new_register(T_OBJECT);
1989       __ move(LIR_OprFact::oopConst(NULL), obj);
1990     }
1991     // Emit an explicit null check because the offset is too large.
1992     // If the class is not loaded and the object is NULL, we need to deoptimize to throw a
1993     // NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.
1994     __ null_check(obj, new CodeEmitInfo(info), /* deoptimize */ needs_patching);
1995   }
1996 
1997   DecoratorSet decorators = IN_HEAP;
1998   if (is_volatile) {




1526       value.load_byte_item();
1527     } else  {
1528       value.load_item();
1529     }
1530   } else {
1531     value.load_for_store(field_type);
1532   }
1533 
1534   set_no_result(x);
1535 
1536 #ifndef PRODUCT
1537   if (PrintNotLoaded && needs_patching) {
1538     tty->print_cr("   ###class not loaded at store_%s bci %d",
1539                   x->is_static() ?  "static" : "field", x->printable_bci());
1540   }
1541 #endif
1542 
1543   if (x->needs_null_check() &&
1544       (needs_patching ||
1545        MacroAssembler::needs_explicit_null_check(x->offset()))) {
1546     if (needs_patching && x->field()->is_flattenable()) {
1547       // We are storing a field of type "QT;" into holder class H, but H is not yet
1548       // loaded. (If H had been loaded, then T must also have already been loaded
1549       // due to the "Q" signature, and needs_patching would be false).
1550       assert(!x->field()->holder()->is_loaded(), "must be");
1551       // We don't know the offset of this field. Let's deopt and recompile.
1552       CodeStub* stub = new DeoptimizeStub(new CodeEmitInfo(info),
1553                                           Deoptimization::Reason_unloaded,
1554                                           Deoptimization::Action_make_not_entrant);
1555       __ branch(lir_cond_always, T_ILLEGAL, stub);
1556     } else {
1557       // Emit an explicit null check because the offset is too large.
1558       // If the class is not loaded and the object is NULL, we need to deoptimize to throw a
1559       // NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.
1560       __ null_check(object.result(), new CodeEmitInfo(info), /* deoptimize */ needs_patching);
1561     }
1562   }
1563 
1564   DecoratorSet decorators = IN_HEAP;
1565   if (is_volatile) {
1566     decorators |= MO_SEQ_CST;


1854   decorators |= ACCESS_WRITE;
1855   // Atomic operations are SEQ_CST by default
1856   decorators |= ((decorators & MO_DECORATOR_MASK) != 0) ? MO_SEQ_CST : 0;
1857   LIRAccess access(this, decorators, base, offset, type);
1858   if (access.is_raw()) {
1859     return _barrier_set->BarrierSetC1::atomic_add_at(access, value);
1860   } else {
1861     return _barrier_set->atomic_add_at(access, value);
1862   }
1863 }
1864 
1865 LIR_Opr LIRGenerator::access_resolve(DecoratorSet decorators, LIR_Opr obj) {
1866   // Use stronger ACCESS_WRITE|ACCESS_READ by default.
1867   if ((decorators & (ACCESS_READ | ACCESS_WRITE)) == 0) {
1868     decorators |= ACCESS_READ | ACCESS_WRITE;
1869   }
1870 
1871   return _barrier_set->resolve(this, decorators, obj);
1872 }
1873 
1874 Value LIRGenerator::flattenable_load_field_prolog(LoadField* x, CodeEmitInfo* info) {
1875   ciField* field = x->field();
1876   ciInstanceKlass* holder = field->holder();
1877   Value default_value = NULL;
1878 
1879   // Unloaded "QV;" klasses are represented by a ciInstanceKlass
1880   bool field_type_unloaded = field->type()->is_instance_klass() && !field->type()->as_instance_klass()->is_loaded();
1881 
1882   // Check for edge cases (1), (2) and (3) for getstatic and getfield
1883   bool deopt = false;
1884   bool need_default = false;
1885   if (field->is_static()) {
1886       // (1) holder is unloaded -- no problem: it will be loaded by patching, and field offset will be determined.
1887       // No check needed here.
1888 
1889     if (field_type_unloaded) {
1890       // (2) field type is unloaded -- problem: we don't know what the default value is. Let's deopt.
1891       //                               FIXME: consider getting the default value in patching code.
1892       deopt = true;
1893     } else {
1894       need_default = true;
1895     }
1896 
1897       // (3) field is not flattened -- we don't care: static fields are never flattened.
1898       // No check needed here.
1899   } else {
1900     if (!holder->is_loaded()) {
1901       // (1) holder is unloaded -- problem: we needed the field offset back in GraphBuilder::access_field()
1902       //                           FIXME: consider getting field offset in patching code (but only if the field
1903       //                           type was loaded at compilation time).
1904       deopt = true;
1905     } else if (field_type_unloaded) {
1906       // (2) field type is unloaded -- problem: we don't know whether it's flattened or not. Let's deopt
1907       deopt = true;
1908     } else if (!field->is_flattened()) {
1909       // (3) field is not flattened -- need default value in cases of uninitialized field
1910       need_default = true;
1911     }
1912   }
1913 


1914   if (deopt) {
1915     assert(!need_default, "deopt and need_default cannot both be true");
1916     assert(x->needs_patching(), "must be");
1917     assert(info != NULL, "must be");
1918     CodeStub* stub = new DeoptimizeStub(new CodeEmitInfo(info),
1919                                         Deoptimization::Reason_unloaded,
1920                                         Deoptimization::Action_make_not_entrant);
1921     __ branch(lir_cond_always, T_ILLEGAL, stub);
1922   } else if (need_default) {
1923     assert(!field_type_unloaded, "must be");
1924     assert(field->type()->is_valuetype(), "must be");
1925     ciValueKlass* value_klass = field->type()->as_value_klass();
1926     assert(value_klass->is_loaded(), "must be");
1927 
1928     if (field->is_static() && holder->is_loaded()) {
1929       ciInstance* mirror = field->holder()->java_mirror();
1930       ciObject* val = mirror->field_value(field).as_object();
1931       if (val->is_null_object()) {
1932         // This is a non-nullable static field, but it's not initialized.
1933         // We need to do a null check, and replace it with the default value.
1934       } else {
1935         // No need to perform null check on this static field


1958     NullCheck* nc = x->explicit_null_check();
1959     if (nc == NULL) {
1960       info = state_for(x);
1961     } else {
1962       info = state_for(nc);
1963     }
1964   }
1965 
1966   LIRItem object(x->obj(), this);
1967 
1968   object.load_item();
1969 
1970 #ifndef PRODUCT
1971   if (PrintNotLoaded && needs_patching) {
1972     tty->print_cr("   ###class not loaded at load_%s bci %d",
1973                   x->is_static() ?  "static" : "field", x->printable_bci());
1974   }
1975 #endif
1976 
1977   Value default_value = NULL;
1978   if (x->field()->is_flattenable()) {
1979     default_value = flattenable_load_field_prolog(x, info);
1980   }
1981 
1982   bool stress_deopt = StressLoopInvariantCodeMotion && info && info->deoptimize_on_exception();
1983   if (x->needs_null_check() &&
1984       (needs_patching ||
1985        MacroAssembler::needs_explicit_null_check(x->offset()) ||
1986        stress_deopt)) {
1987     LIR_Opr obj = object.result();
1988     if (stress_deopt) {
1989       obj = new_register(T_OBJECT);
1990       __ move(LIR_OprFact::oopConst(NULL), obj);
1991     }
1992     // Emit an explicit null check because the offset is too large.
1993     // If the class is not loaded and the object is NULL, we need to deoptimize to throw a
1994     // NoClassDefFoundError in the interpreter instead of an implicit NPE from compiled code.
1995     __ null_check(obj, new CodeEmitInfo(info), /* deoptimize */ needs_patching);
1996   }
1997 
1998   DecoratorSet decorators = IN_HEAP;
1999   if (is_volatile) {


< prev index next >