mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8283417: Update java.nio buffers to use sealed classes
Reviewed-by: rriggs, darcy, iris, alanb
This commit is contained in:
parent
19f01ab701
commit
b36cf35ad9
7 changed files with 45 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2000, 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
|
||||||
|
@ -191,7 +191,9 @@ import java.util.Spliterator;
|
||||||
* @since 1.4
|
* @since 1.4
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public abstract class Buffer {
|
public abstract sealed class Buffer
|
||||||
|
permits ByteBuffer, CharBuffer, DoubleBuffer, FloatBuffer, IntBuffer,
|
||||||
|
LongBuffer, ShortBuffer {
|
||||||
// Cached unsafe-access object
|
// Cached unsafe-access object
|
||||||
static final Unsafe UNSAFE = Unsafe.getUnsafe();
|
static final Unsafe UNSAFE = Unsafe.getUnsafe();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2000, 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
|
||||||
|
@ -31,8 +31,16 @@ import java.util.Objects;
|
||||||
import jdk.internal.access.foreign.MemorySegmentProxy;
|
import jdk.internal.access.foreign.MemorySegmentProxy;
|
||||||
import jdk.internal.misc.Unsafe;
|
import jdk.internal.misc.Unsafe;
|
||||||
|
|
||||||
|
#if[rw]
|
||||||
|
sealed
|
||||||
|
#else[rw]
|
||||||
|
final
|
||||||
|
#end[rw]
|
||||||
class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
|
class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
|
||||||
extends {#if[ro]?ByteBufferAs}$Type$Buffer{#if[ro]?$BO$}
|
extends {#if[ro]?ByteBufferAs}$Type$Buffer{#if[ro]?$BO$}
|
||||||
|
#if[rw]
|
||||||
|
permits ByteBufferAs$Type$BufferR$BO$
|
||||||
|
#end[rw]
|
||||||
{
|
{
|
||||||
|
|
||||||
#if[rw]
|
#if[rw]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2000, 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
|
||||||
|
@ -37,6 +37,11 @@ import jdk.internal.ref.Cleaner;
|
||||||
import sun.nio.ch.DirectBuffer;
|
import sun.nio.ch.DirectBuffer;
|
||||||
|
|
||||||
|
|
||||||
|
#if[rw]
|
||||||
|
sealed
|
||||||
|
#else[rw]
|
||||||
|
final
|
||||||
|
#end[rw]
|
||||||
class Direct$Type$Buffer$RW$$BO$
|
class Direct$Type$Buffer$RW$$BO$
|
||||||
#if[rw]
|
#if[rw]
|
||||||
extends {#if[byte]?Mapped$Type$Buffer:$Type$Buffer}
|
extends {#if[byte]?Mapped$Type$Buffer:$Type$Buffer}
|
||||||
|
@ -44,6 +49,9 @@ class Direct$Type$Buffer$RW$$BO$
|
||||||
extends Direct$Type$Buffer$BO$
|
extends Direct$Type$Buffer$BO$
|
||||||
#end[rw]
|
#end[rw]
|
||||||
implements DirectBuffer
|
implements DirectBuffer
|
||||||
|
#if[rw]
|
||||||
|
permits Direct$Type$BufferR$BO$
|
||||||
|
#end[rw]
|
||||||
{
|
{
|
||||||
|
|
||||||
#if[rw]
|
#if[rw]
|
||||||
|
|
|
@ -40,8 +40,16 @@ import jdk.internal.access.foreign.MemorySegmentProxy;
|
||||||
* instance of this class rather than of the superclass.
|
* instance of this class rather than of the superclass.
|
||||||
#end[rw]
|
#end[rw]
|
||||||
*/
|
*/
|
||||||
|
#if[rw]
|
||||||
|
sealed
|
||||||
|
#else[rw]
|
||||||
|
final
|
||||||
|
#end[rw]
|
||||||
class Heap$Type$Buffer$RW$
|
class Heap$Type$Buffer$RW$
|
||||||
extends {#if[ro]?Heap}$Type$Buffer
|
extends {#if[ro]?Heap}$Type$Buffer
|
||||||
|
#if[rw]
|
||||||
|
permits Heap$Type$BufferR
|
||||||
|
#end[rw]
|
||||||
{
|
{
|
||||||
#if[rw]
|
#if[rw]
|
||||||
// Cached array base offset
|
// Cached array base offset
|
||||||
|
|
|
@ -70,8 +70,9 @@ import jdk.internal.misc.Unsafe;
|
||||||
* @since 1.4
|
* @since 1.4
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public abstract class MappedByteBuffer
|
public abstract sealed class MappedByteBuffer
|
||||||
extends ByteBuffer
|
extends ByteBuffer
|
||||||
|
permits DirectByteBuffer
|
||||||
{
|
{
|
||||||
|
|
||||||
// This is a little bit backwards: By rights MappedByteBuffer should be a
|
// This is a little bit backwards: By rights MappedByteBuffer should be a
|
||||||
|
|
|
@ -29,7 +29,7 @@ import java.util.Objects;
|
||||||
|
|
||||||
// ## If the sequence is a string, use reflection to share its array
|
// ## If the sequence is a string, use reflection to share its array
|
||||||
|
|
||||||
class StringCharBuffer // package-private
|
final class StringCharBuffer // package-private
|
||||||
extends CharBuffer
|
extends CharBuffer
|
||||||
{
|
{
|
||||||
CharSequence str;
|
CharSequence str;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2000, 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
|
||||||
|
@ -264,9 +264,19 @@ import jdk.internal.util.ArraysSupport;
|
||||||
* @since 1.4
|
* @since 1.4
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public abstract class $Type$Buffer
|
public abstract sealed class $Type$Buffer
|
||||||
extends Buffer
|
extends Buffer
|
||||||
implements Comparable<$Type$Buffer>{#if[char]?, Appendable, CharSequence, Readable}
|
implements Comparable<$Type$Buffer>{#if[char]?, Appendable, CharSequence, Readable}
|
||||||
|
permits
|
||||||
|
#if[byte]
|
||||||
|
Heap$Type$Buffer, MappedByteBuffer
|
||||||
|
#else[byte]
|
||||||
|
#if[char]
|
||||||
|
StringCharBuffer,
|
||||||
|
#end[char]
|
||||||
|
Heap$Type$Buffer, Direct$Type$BufferS, Direct$Type$BufferU,
|
||||||
|
ByteBufferAs$Type$BufferB, ByteBufferAs$Type$BufferL
|
||||||
|
#end[byte]
|
||||||
{
|
{
|
||||||
// Cached array base offset
|
// Cached array base offset
|
||||||
private static final long ARRAY_BASE_OFFSET = UNSAFE.arrayBaseOffset($type$[].class);
|
private static final long ARRAY_BASE_OFFSET = UNSAFE.arrayBaseOffset($type$[].class);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue