8283415: Update java.lang.ref to use sealed classes

Reviewed-by: kbarrett, alanb
This commit is contained in:
Joe Darcy 2022-03-21 16:57:17 +00:00
parent f4f87284cb
commit 14b9e80b8a
5 changed files with 11 additions and 10 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,7 @@ package java.lang.ref;
/** /**
* Final references, used to implement finalization * Final references, used to implement finalization
*/ */
class FinalReference<T> extends Reference<T> { sealed class FinalReference<T> extends Reference<T> permits Finalizer {
public FinalReference(T referent, ReferenceQueue<? super T> q) { public FinalReference(T referent, ReferenceQueue<? super T> q) {
super(referent, q); super(referent, q);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -50,7 +50,7 @@ import jdk.internal.vm.annotation.IntrinsicCandidate;
* @since 1.2 * @since 1.2
*/ */
public class PhantomReference<T> extends Reference<T> { public non-sealed class PhantomReference<T> extends Reference<T> {
/** /**
* Returns this reference object's referent. Because the referent of a * Returns this reference object's referent. Because the referent of a

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -41,7 +41,8 @@ import jdk.internal.ref.Cleaner;
* @since 1.2 * @since 1.2
*/ */
public abstract class Reference<T> { public abstract sealed class Reference<T>
permits PhantomReference, SoftReference, WeakReference, FinalReference {
/* The state of a Reference object is characterized by two attributes. It /* The state of a Reference object is characterized by two attributes. It
* may be either "active", "pending", or "inactive". It may also be * may be either "active", "pending", or "inactive". It may also be

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -61,7 +61,7 @@ package java.lang.ref;
* @since 1.2 * @since 1.2
*/ */
public class SoftReference<T> extends Reference<T> { public non-sealed class SoftReference<T> extends Reference<T> {
/** /**
* Timestamp clock, updated by the garbage collector * Timestamp clock, updated by the garbage collector

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -45,7 +45,7 @@ package java.lang.ref;
* @since 1.2 * @since 1.2
*/ */
public class WeakReference<T> extends Reference<T> { public non-sealed class WeakReference<T> extends Reference<T> {
/** /**
* Creates a new weak reference that refers to the given object. The new * Creates a new weak reference that refers to the given object. The new