41 void referenceProcessor_init() { |
41 void referenceProcessor_init() { |
42 ReferenceProcessor::init_statics(); |
42 ReferenceProcessor::init_statics(); |
43 } |
43 } |
44 |
44 |
45 void ReferenceProcessor::init_statics() { |
45 void ReferenceProcessor::init_statics() { |
46 jlong now = os::javaTimeMillis(); |
46 // We need a monotonically non-deccreasing time in ms but |
|
47 // os::javaTimeMillis() does not guarantee monotonicity. |
|
48 jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC; |
47 |
49 |
48 // Initialize the soft ref timestamp clock. |
50 // Initialize the soft ref timestamp clock. |
49 _soft_ref_timestamp_clock = now; |
51 _soft_ref_timestamp_clock = now; |
50 // Also update the soft ref clock in j.l.r.SoftReference |
52 // Also update the soft ref clock in j.l.r.SoftReference |
51 java_lang_ref_SoftReference::set_clock(_soft_ref_timestamp_clock); |
53 java_lang_ref_SoftReference::set_clock(_soft_ref_timestamp_clock); |
149 } |
151 } |
150 |
152 |
151 void ReferenceProcessor::update_soft_ref_master_clock() { |
153 void ReferenceProcessor::update_soft_ref_master_clock() { |
152 // Update (advance) the soft ref master clock field. This must be done |
154 // Update (advance) the soft ref master clock field. This must be done |
153 // after processing the soft ref list. |
155 // after processing the soft ref list. |
154 jlong now = os::javaTimeMillis(); |
156 |
|
157 // We need a monotonically non-deccreasing time in ms but |
|
158 // os::javaTimeMillis() does not guarantee monotonicity. |
|
159 jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC; |
155 jlong soft_ref_clock = java_lang_ref_SoftReference::clock(); |
160 jlong soft_ref_clock = java_lang_ref_SoftReference::clock(); |
156 assert(soft_ref_clock == _soft_ref_timestamp_clock, "soft ref clocks out of sync"); |
161 assert(soft_ref_clock == _soft_ref_timestamp_clock, "soft ref clocks out of sync"); |
157 |
162 |
158 NOT_PRODUCT( |
163 NOT_PRODUCT( |
159 if (now < _soft_ref_timestamp_clock) { |
164 if (now < _soft_ref_timestamp_clock) { |
160 warning("time warp: "INT64_FORMAT" to "INT64_FORMAT, |
165 warning("time warp: "INT64_FORMAT" to "INT64_FORMAT, |
161 _soft_ref_timestamp_clock, now); |
166 _soft_ref_timestamp_clock, now); |
162 } |
167 } |
163 ) |
168 ) |
164 // In product mode, protect ourselves from system time being adjusted |
169 // The values of now and _soft_ref_timestamp_clock are set using |
165 // externally and going backward; see note in the implementation of |
170 // javaTimeNanos(), which is guaranteed to be monotonically |
166 // GenCollectedHeap::time_since_last_gc() for the right way to fix |
171 // non-decreasing provided the underlying platform provides such |
167 // this uniformly throughout the VM; see bug-id 4741166. XXX |
172 // a time source (and it is bug free). |
|
173 // In product mode, however, protect ourselves from non-monotonicty. |
168 if (now > _soft_ref_timestamp_clock) { |
174 if (now > _soft_ref_timestamp_clock) { |
169 _soft_ref_timestamp_clock = now; |
175 _soft_ref_timestamp_clock = now; |
170 java_lang_ref_SoftReference::set_clock(now); |
176 java_lang_ref_SoftReference::set_clock(now); |
171 } |
177 } |
172 // Else leave clock stalled at its old value until time progresses |
178 // Else leave clock stalled at its old value until time progresses |