8343188: Investigate ways to simplify MemorySegment::ofBuffer

Reviewed-by: mcimadamore
This commit is contained in:
Per Minborg 2024-11-04 11:06:25 +00:00
parent 7f131a9e1e
commit f69b6016d6
9 changed files with 307 additions and 66 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -28,6 +28,10 @@
package java.nio;
import java.lang.foreign.MemorySegment;
import jdk.internal.foreign.AbstractMemorySegmentImpl;
import jdk.internal.foreign.MemorySessionImpl;
import jdk.internal.foreign.SegmentFactories;
import jdk.internal.vm.annotation.ForceInline;
import java.util.Objects;
import jdk.internal.misc.Unsafe;
@ -246,6 +250,21 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
#end[char]
@ForceInline
@Override
int scaleShifts() {
return Integer.numberOfTrailingZeros($Fulltype$.BYTES);
}
@ForceInline
@Override
AbstractMemorySegmentImpl heapSegment(Object base,
long offset,
long length,
boolean readOnly,
MemorySessionImpl bufferScope) {
return SegmentFactories.arrayOfByteSegment(base, offset, length, readOnly, bufferScope);
}
public ByteOrder order() {
#if[boB]