< prev index next >
src/java.base/share/classes/java/nio/MappedByteBuffer.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2000, 2013, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2000, 2018, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 88,101 ****
MappedByteBuffer(int mark, int pos, int lim, int cap) { // package-private
super(mark, pos, lim, cap);
this.fd = null;
}
! private void checkMapped() {
! if (fd == null)
! // Can only happen if a luser explicitly casts a direct byte buffer
! throw new UnsupportedOperationException();
}
// Returns the distance (in bytes) of the buffer from the page aligned address
// of the mapping. Computed each time to avoid storing in every direct buffer.
private long mappingOffset() {
--- 88,99 ----
MappedByteBuffer(int mark, int pos, int lim, int cap) { // package-private
super(mark, pos, lim, cap);
this.fd = null;
}
! private boolean hasMappedFile() {
! return fd != null;
}
// Returns the distance (in bytes) of the buffer from the page aligned address
// of the mapping. Computed each time to avoid storing in every direct buffer.
private long mappingOffset() {
*** 129,139 ****
*
* @return {@code true} if it is likely that this buffer's content
* is resident in physical memory
*/
public final boolean isLoaded() {
! checkMapped();
if ((address == 0) || (capacity() == 0))
return true;
long offset = mappingOffset();
long length = mappingLength(offset);
return isLoaded0(mappingAddress(offset), length, Bits.pageCount(length));
--- 127,139 ----
*
* @return {@code true} if it is likely that this buffer's content
* is resident in physical memory
*/
public final boolean isLoaded() {
! if (!hasMappedFile()) {
! return true;
! }
if ((address == 0) || (capacity() == 0))
return true;
long offset = mappingOffset();
long length = mappingLength(offset);
return isLoaded0(mappingAddress(offset), length, Bits.pageCount(length));
*** 151,161 ****
* occur. </p>
*
* @return This buffer
*/
public final MappedByteBuffer load() {
! checkMapped();
if ((address == 0) || (capacity() == 0))
return this;
long offset = mappingOffset();
long length = mappingLength(offset);
load0(mappingAddress(offset), length);
--- 151,163 ----
* occur. </p>
*
* @return This buffer
*/
public final MappedByteBuffer load() {
! if (!hasMappedFile()) {
! return this;
! }
if ((address == 0) || (capacity() == 0))
return this;
long offset = mappingOffset();
long length = mappingLength(offset);
load0(mappingAddress(offset), length);
*** 195,205 ****
* method has no effect. </p>
*
* @return This buffer
*/
public final MappedByteBuffer force() {
! checkMapped();
if ((address != 0) && (capacity() != 0)) {
long offset = mappingOffset();
force0(fd, mappingAddress(offset), mappingLength(offset));
}
return this;
--- 197,209 ----
* method has no effect. </p>
*
* @return This buffer
*/
public final MappedByteBuffer force() {
! if (!hasMappedFile()) {
! return this;
! }
if ((address != 0) && (capacity() != 0)) {
long offset = mappingOffset();
force0(fd, mappingAddress(offset), mappingLength(offset));
}
return this;
< prev index next >