86 if (DTraceMonitorProbes) { \
87 DTRACE_MONITOR_PROBE_COMMON(obj, thread); \
88 HOTSPOT_MONITOR_##probe(jtid, \
89 (uintptr_t)(monitor), bytes, len); \
90 } \
91 }
92
93 #else // ndef DTRACE_ENABLED
94
95 #define DTRACE_MONITOR_WAIT_PROBE(obj, thread, millis, mon) {;}
96 #define DTRACE_MONITOR_PROBE(probe, obj, thread, mon) {;}
97
98 #endif // ndef DTRACE_ENABLED
99
100 // Tunables ...
101 // The knob* variables are effectively final. Once set they should
102 // never be modified hence. Consider using __read_mostly with GCC.
103
104 int ObjectMonitor::Knob_SpinLimit = 5000; // derived by an external tool -
105
106 static int Knob_CASPenalty = -1; // Penalty for failed CAS
107 static int Knob_OXPenalty = -1; // Penalty for observed _owner change
108 static int Knob_SpinSetSucc = 1; // spinners set the _succ field
109 static int Knob_SpinEarly = 1;
110 static int Knob_SuccEnabled = 1; // futile wake throttling
111 static int Knob_SuccRestrict = 0; // Limit successors + spinners to at-most-one
112 static int Knob_MaxSpinners = -1; // Should be a function of # CPUs
113 static int Knob_Bonus = 100; // spin success bonus
114 static int Knob_BonusB = 100; // spin success bonus
115 static int Knob_Penalty = 200; // spin failure penalty
116 static int Knob_Poverty = 1000;
117 static int Knob_SpinAfterFutile = 1; // Spin after returning from park()
118 static int Knob_FixedSpin = 0;
119 static int Knob_OState = 3; // Spinner checks thread state of _owner
120 static int Knob_UsePause = 1;
121 static int Knob_ExitPolicy = 0;
122 static int Knob_PreSpin = 10; // 20-100 likely better
123 static int Knob_ResetEvent = 0;
124
125 static int Knob_FastHSSEC = 0;
126 static int Knob_MoveNotifyee = 2; // notify() - disposition of notifyee
1848 if (ctr <= 0) return 0;
1849
1850 if (Knob_SuccRestrict && _succ != NULL) return 0;
1851 if (Knob_OState && NotRunnable (Self, (Thread *) _owner)) {
1852 return 0;
1853 }
1854
1855 int MaxSpin = Knob_MaxSpinners;
1856 if (MaxSpin >= 0) {
1857 if (_Spinner > MaxSpin) {
1858 return 0;
1859 }
1860 // Slightly racy, but benign ...
1861 Adjust(&_Spinner, 1);
1862 }
1863
1864 // We're good to spin ... spin ingress.
1865 // CONSIDER: use Prefetch::write() to avoid RTS->RTO upgrades
1866 // when preparing to LD...CAS _owner, etc and the CAS is likely
1867 // to succeed.
1868 int caspty = Knob_CASPenalty;
1869 int oxpty = Knob_OXPenalty;
1870 int sss = Knob_SpinSetSucc;
1871 if (sss && _succ == NULL) _succ = Self;
1872 Thread * prv = NULL;
1873
1874 // There are three ways to exit the following loop:
1875 // 1. A successful spin where this thread has acquired the lock.
1876 // 2. Spin failure with prejudice
1877 // 3. Spin failure without prejudice
1878
1879 while (--ctr >= 0) {
1880
1881 // Periodic polling -- Check for pending GC
1882 // Threads may spin while they're unsafe.
1883 // We don't want spinning threads to delay the JVM from reaching
1884 // a stop-the-world safepoint or to steal cycles from GC.
1885 // If we detect a pending safepoint we abort in order that
1886 // (a) this thread, if unsafe, doesn't delay the safepoint, and (b)
1887 // this thread, if safe, doesn't steal cycles from GC.
1888 // This is in keeping with the "no loitering in runtime" rule.
1916 _succ = NULL;
1917 }
1918 if (MaxSpin > 0) Adjust(&_Spinner, -1);
1919
1920 // Increase _SpinDuration :
1921 // The spin was successful (profitable) so we tend toward
1922 // longer spin attempts in the future.
1923 // CONSIDER: factor "ctr" into the _SpinDuration adjustment.
1924 // If we acquired the lock early in the spin cycle it
1925 // makes sense to increase _SpinDuration proportionally.
1926 // Note that we don't clamp SpinDuration precisely at SpinLimit.
1927 int x = _SpinDuration;
1928 if (x < Knob_SpinLimit) {
1929 if (x < Knob_Poverty) x = Knob_Poverty;
1930 _SpinDuration = x + Knob_Bonus;
1931 }
1932 return 1;
1933 }
1934
1935 // The CAS failed ... we can take any of the following actions:
1936 // * penalize: ctr -= Knob_CASPenalty
1937 // * exit spin with prejudice -- goto Abort;
1938 // * exit spin without prejudice.
1939 // * Since CAS is high-latency, retry again immediately.
1940 prv = ox;
1941 if (caspty == -2) break;
1942 if (caspty == -1) goto Abort;
1943 ctr -= caspty;
1944 continue;
1945 }
1946
1947 // Did lock ownership change hands ?
1948 if (ox != prv && prv != NULL) {
1949 if (oxpty == -2) break;
1950 if (oxpty == -1) goto Abort;
1951 ctr -= oxpty;
1952 }
1953 prv = ox;
1954
1955 // Abort the spin if the owner is not executing.
1956 // The owner must be executing in order to drop the lock.
1957 // Spinning while the owner is OFFPROC is idiocy.
1958 // Consider: ctr -= RunnablePenalty ;
1959 if (Knob_OState && NotRunnable (Self, ox)) {
1960 goto Abort;
1961 }
1962 if (sss && _succ == NULL) _succ = Self;
1963 }
1964
|
86 if (DTraceMonitorProbes) { \
87 DTRACE_MONITOR_PROBE_COMMON(obj, thread); \
88 HOTSPOT_MONITOR_##probe(jtid, \
89 (uintptr_t)(monitor), bytes, len); \
90 } \
91 }
92
93 #else // ndef DTRACE_ENABLED
94
95 #define DTRACE_MONITOR_WAIT_PROBE(obj, thread, millis, mon) {;}
96 #define DTRACE_MONITOR_PROBE(probe, obj, thread, mon) {;}
97
98 #endif // ndef DTRACE_ENABLED
99
100 // Tunables ...
101 // The knob* variables are effectively final. Once set they should
102 // never be modified hence. Consider using __read_mostly with GCC.
103
104 int ObjectMonitor::Knob_SpinLimit = 5000; // derived by an external tool -
105
106 static int Knob_OXPenalty = -1; // Penalty for observed _owner change
107 static int Knob_SpinSetSucc = 1; // spinners set the _succ field
108 static int Knob_SpinEarly = 1;
109 static int Knob_SuccEnabled = 1; // futile wake throttling
110 static int Knob_SuccRestrict = 0; // Limit successors + spinners to at-most-one
111 static int Knob_MaxSpinners = -1; // Should be a function of # CPUs
112 static int Knob_Bonus = 100; // spin success bonus
113 static int Knob_BonusB = 100; // spin success bonus
114 static int Knob_Penalty = 200; // spin failure penalty
115 static int Knob_Poverty = 1000;
116 static int Knob_SpinAfterFutile = 1; // Spin after returning from park()
117 static int Knob_FixedSpin = 0;
118 static int Knob_OState = 3; // Spinner checks thread state of _owner
119 static int Knob_UsePause = 1;
120 static int Knob_ExitPolicy = 0;
121 static int Knob_PreSpin = 10; // 20-100 likely better
122 static int Knob_ResetEvent = 0;
123
124 static int Knob_FastHSSEC = 0;
125 static int Knob_MoveNotifyee = 2; // notify() - disposition of notifyee
1847 if (ctr <= 0) return 0;
1848
1849 if (Knob_SuccRestrict && _succ != NULL) return 0;
1850 if (Knob_OState && NotRunnable (Self, (Thread *) _owner)) {
1851 return 0;
1852 }
1853
1854 int MaxSpin = Knob_MaxSpinners;
1855 if (MaxSpin >= 0) {
1856 if (_Spinner > MaxSpin) {
1857 return 0;
1858 }
1859 // Slightly racy, but benign ...
1860 Adjust(&_Spinner, 1);
1861 }
1862
1863 // We're good to spin ... spin ingress.
1864 // CONSIDER: use Prefetch::write() to avoid RTS->RTO upgrades
1865 // when preparing to LD...CAS _owner, etc and the CAS is likely
1866 // to succeed.
1867 int oxpty = Knob_OXPenalty;
1868 int sss = Knob_SpinSetSucc;
1869 if (sss && _succ == NULL) _succ = Self;
1870 Thread * prv = NULL;
1871
1872 // There are three ways to exit the following loop:
1873 // 1. A successful spin where this thread has acquired the lock.
1874 // 2. Spin failure with prejudice
1875 // 3. Spin failure without prejudice
1876
1877 while (--ctr >= 0) {
1878
1879 // Periodic polling -- Check for pending GC
1880 // Threads may spin while they're unsafe.
1881 // We don't want spinning threads to delay the JVM from reaching
1882 // a stop-the-world safepoint or to steal cycles from GC.
1883 // If we detect a pending safepoint we abort in order that
1884 // (a) this thread, if unsafe, doesn't delay the safepoint, and (b)
1885 // this thread, if safe, doesn't steal cycles from GC.
1886 // This is in keeping with the "no loitering in runtime" rule.
1914 _succ = NULL;
1915 }
1916 if (MaxSpin > 0) Adjust(&_Spinner, -1);
1917
1918 // Increase _SpinDuration :
1919 // The spin was successful (profitable) so we tend toward
1920 // longer spin attempts in the future.
1921 // CONSIDER: factor "ctr" into the _SpinDuration adjustment.
1922 // If we acquired the lock early in the spin cycle it
1923 // makes sense to increase _SpinDuration proportionally.
1924 // Note that we don't clamp SpinDuration precisely at SpinLimit.
1925 int x = _SpinDuration;
1926 if (x < Knob_SpinLimit) {
1927 if (x < Knob_Poverty) x = Knob_Poverty;
1928 _SpinDuration = x + Knob_Bonus;
1929 }
1930 return 1;
1931 }
1932
1933 // The CAS failed ... we can take any of the following actions:
1934 // * penalize: ctr -= CASPenalty
1935 // * exit spin with prejudice -- goto Abort;
1936 // * exit spin without prejudice.
1937 // * Since CAS is high-latency, retry again immediately.
1938 prv = ox;
1939 goto Abort;
1940 }
1941
1942 // Did lock ownership change hands ?
1943 if (ox != prv && prv != NULL) {
1944 if (oxpty == -2) break;
1945 if (oxpty == -1) goto Abort;
1946 ctr -= oxpty;
1947 }
1948 prv = ox;
1949
1950 // Abort the spin if the owner is not executing.
1951 // The owner must be executing in order to drop the lock.
1952 // Spinning while the owner is OFFPROC is idiocy.
1953 // Consider: ctr -= RunnablePenalty ;
1954 if (Knob_OState && NotRunnable (Self, ox)) {
1955 goto Abort;
1956 }
1957 if (sss && _succ == NULL) _succ = Self;
1958 }
1959
|