< prev index next >

src/hotspot/share/runtime/synchronizer.cpp

Print this page
rev 59856 : 8247280: more fencing needed in async deflation for non-TSO machines
Reviewed-by: dholmes


1891       // with this thread we could simply set m->_owner = self.
1892       // Note that a thread can inflate an object
1893       // that it has stack-locked -- as might happen in wait() -- directly
1894       // with CAS.  That is, we can avoid the xchg-NULL .... ST idiom.
1895       if (AsyncDeflateIdleMonitors) {
1896         m->set_owner_from(NULL, DEFLATER_MARKER, mark.locker());
1897       } else {
1898         m->set_owner_from(NULL, mark.locker());
1899       }
1900       m->set_object(object);
1901       // TODO-FIXME: assert BasicLock->dhw != 0.
1902 
1903       // Must preserve store ordering. The monitor state must
1904       // be stable at the time of publishing the monitor address.
1905       guarantee(object->mark() == markWord::INFLATING(), "invariant");
1906       object->release_set_mark(markWord::encode(m));
1907 
1908       // Once ObjectMonitor is configured and the object is associated
1909       // with the ObjectMonitor, it is safe to allow async deflation:
1910       assert(m->is_new(), "freshly allocated monitor must be new");
1911       m->set_allocation_state(ObjectMonitor::Old);

1912 
1913       // Hopefully the performance counters are allocated on distinct cache lines
1914       // to avoid false sharing on MP systems ...
1915       OM_PERFDATA_OP(Inflations, inc());
1916       if (log_is_enabled(Trace, monitorinflation)) {
1917         ResourceMark rm(self);
1918         lsh.print_cr("inflate(has_locker): object=" INTPTR_FORMAT ", mark="
1919                      INTPTR_FORMAT ", type='%s'", p2i(object),
1920                      object->mark().value(), object->klass()->external_name());
1921       }
1922       if (event.should_commit()) {
1923         post_monitor_inflate_event(&event, object, cause);
1924       }
1925       return m;
1926     }
1927 
1928     // CASE: neutral
1929     // TODO-FIXME: for entry we currently inflate and then try to CAS _owner.
1930     // If we know we're inflating for entry it's better to inflate by swinging a
1931     // pre-locked ObjectMonitor pointer into the object header.   A successful


1948     m->set_object(object);
1949     m->_Responsible  = NULL;
1950     m->_SpinDuration = ObjectMonitor::Knob_SpinLimit;       // consider: keep metastats by type/class
1951 
1952     if (object->cas_set_mark(markWord::encode(m), mark) != mark) {
1953       m->set_header(markWord::zero());
1954       m->set_object(NULL);
1955       m->Recycle();
1956       // om_release() will reset the allocation state from New to Free.
1957       om_release(self, m, true);
1958       m = NULL;
1959       continue;
1960       // interference - the markword changed - just retry.
1961       // The state-transitions are one-way, so there's no chance of
1962       // live-lock -- "Inflated" is an absorbing state.
1963     }
1964 
1965     // Once the ObjectMonitor is configured and object is associated
1966     // with the ObjectMonitor, it is safe to allow async deflation:
1967     assert(m->is_new(), "freshly allocated monitor must be new");


1968     m->set_allocation_state(ObjectMonitor::Old);
1969 
1970     // Hopefully the performance counters are allocated on distinct
1971     // cache lines to avoid false sharing on MP systems ...
1972     OM_PERFDATA_OP(Inflations, inc());
1973     if (log_is_enabled(Trace, monitorinflation)) {
1974       ResourceMark rm(self);
1975       lsh.print_cr("inflate(neutral): object=" INTPTR_FORMAT ", mark="
1976                    INTPTR_FORMAT ", type='%s'", p2i(object),
1977                    object->mark().value(), object->klass()->external_name());
1978     }
1979     if (event.should_commit()) {
1980       post_monitor_inflate_event(&event, object, cause);
1981     }
1982     return m;
1983   }
1984 }
1985 
1986 
1987 // We maintain a list of in-use monitors for each thread.




1891       // with this thread we could simply set m->_owner = self.
1892       // Note that a thread can inflate an object
1893       // that it has stack-locked -- as might happen in wait() -- directly
1894       // with CAS.  That is, we can avoid the xchg-NULL .... ST idiom.
1895       if (AsyncDeflateIdleMonitors) {
1896         m->set_owner_from(NULL, DEFLATER_MARKER, mark.locker());
1897       } else {
1898         m->set_owner_from(NULL, mark.locker());
1899       }
1900       m->set_object(object);
1901       // TODO-FIXME: assert BasicLock->dhw != 0.
1902 
1903       // Must preserve store ordering. The monitor state must
1904       // be stable at the time of publishing the monitor address.
1905       guarantee(object->mark() == markWord::INFLATING(), "invariant");
1906       object->release_set_mark(markWord::encode(m));
1907 
1908       // Once ObjectMonitor is configured and the object is associated
1909       // with the ObjectMonitor, it is safe to allow async deflation:
1910       assert(m->is_new(), "freshly allocated monitor must be new");
1911       // Release semantics needed to keep allocation_state from floating up.
1912       m->release_set_allocation_state(ObjectMonitor::Old);
1913 
1914       // Hopefully the performance counters are allocated on distinct cache lines
1915       // to avoid false sharing on MP systems ...
1916       OM_PERFDATA_OP(Inflations, inc());
1917       if (log_is_enabled(Trace, monitorinflation)) {
1918         ResourceMark rm(self);
1919         lsh.print_cr("inflate(has_locker): object=" INTPTR_FORMAT ", mark="
1920                      INTPTR_FORMAT ", type='%s'", p2i(object),
1921                      object->mark().value(), object->klass()->external_name());
1922       }
1923       if (event.should_commit()) {
1924         post_monitor_inflate_event(&event, object, cause);
1925       }
1926       return m;
1927     }
1928 
1929     // CASE: neutral
1930     // TODO-FIXME: for entry we currently inflate and then try to CAS _owner.
1931     // If we know we're inflating for entry it's better to inflate by swinging a
1932     // pre-locked ObjectMonitor pointer into the object header.   A successful


1949     m->set_object(object);
1950     m->_Responsible  = NULL;
1951     m->_SpinDuration = ObjectMonitor::Knob_SpinLimit;       // consider: keep metastats by type/class
1952 
1953     if (object->cas_set_mark(markWord::encode(m), mark) != mark) {
1954       m->set_header(markWord::zero());
1955       m->set_object(NULL);
1956       m->Recycle();
1957       // om_release() will reset the allocation state from New to Free.
1958       om_release(self, m, true);
1959       m = NULL;
1960       continue;
1961       // interference - the markword changed - just retry.
1962       // The state-transitions are one-way, so there's no chance of
1963       // live-lock -- "Inflated" is an absorbing state.
1964     }
1965 
1966     // Once the ObjectMonitor is configured and object is associated
1967     // with the ObjectMonitor, it is safe to allow async deflation:
1968     assert(m->is_new(), "freshly allocated monitor must be new");
1969     // Release semantics are not needed to keep allocation_state from
1970     // floating up since cas_set_mark() takes care of it.
1971     m->set_allocation_state(ObjectMonitor::Old);
1972 
1973     // Hopefully the performance counters are allocated on distinct
1974     // cache lines to avoid false sharing on MP systems ...
1975     OM_PERFDATA_OP(Inflations, inc());
1976     if (log_is_enabled(Trace, monitorinflation)) {
1977       ResourceMark rm(self);
1978       lsh.print_cr("inflate(neutral): object=" INTPTR_FORMAT ", mark="
1979                    INTPTR_FORMAT ", type='%s'", p2i(object),
1980                    object->mark().value(), object->klass()->external_name());
1981     }
1982     if (event.should_commit()) {
1983       post_monitor_inflate_event(&event, object, cause);
1984     }
1985     return m;
1986   }
1987 }
1988 
1989 
1990 // We maintain a list of in-use monitors for each thread.


< prev index next >