Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/jcl/src/java.base/share/classes/java/lang/ref/SoftReference.java
12521 views
1
/*[INCLUDE-IF Sidecar16]*/
2
package java.lang.ref;
3
4
/*******************************************************************************
5
* Copyright (c) 1998, 2020 IBM Corp. and others
6
*
7
* This program and the accompanying materials are made available under
8
* the terms of the Eclipse Public License 2.0 which accompanies this
9
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
10
* or the Apache License, Version 2.0 which accompanies this distribution and
11
* is available at https://www.apache.org/licenses/LICENSE-2.0.
12
*
13
* This Source Code may also be made available under the following
14
* Secondary Licenses when the conditions for such availability set
15
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
16
* General Public License, version 2 with the GNU Classpath
17
* Exception [1] and GNU General Public License, version 2 with the
18
* OpenJDK Assembly Exception [2].
19
*
20
* [1] https://www.gnu.org/software/classpath/license.html
21
* [2] http://openjdk.java.net/legal/assembly-exception.html
22
*
23
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
24
*******************************************************************************/
25
26
/**
27
* SoftReference objects are used to detect referents which
28
* are no longer visible and who's memory is to be reclaimed.
29
*
30
* @author OTI
31
* @version initial
32
* @since 1.2
33
*/
34
public class SoftReference<T> extends java.lang.ref.Reference<T> {
35
/*[PR 124242] SoftReference.get() should reset age */
36
private volatile int age;
37
38
/**
39
* Constructs a new instance of this class.
40
*
41
* @param r referent to track.
42
* @param q queue to register to the reference object with.
43
*/
44
public SoftReference(T r, ReferenceQueue<? super T> q) {
45
initReference(r, q);
46
}
47
48
/**
49
* Constructs a new instance of this class.
50
*
51
* @param r referent to track.
52
*/
53
public SoftReference(T r) {
54
initReference(r);
55
}
56
57
/**
58
* Return the referent of the reference object.
59
*
60
* @return Referent to which reference refers,
61
* or null if object has been cleared.
62
*/
63
public T get () {
64
/*[PR 124242] SoftReference.get() should reset age*/
65
if (age != 0) {
66
age = 0;
67
}
68
return super.get();
69
}
70
}
71
72