8196535: Remove support for pre-Java 6 non-JVM-wide file locking

Reviewed-by: alanb, rriggs
This commit is contained in:
Brian Burkhalter 2018-02-05 15:08:46 -08:00
parent 7f04dec594
commit 5f7839ae5a
3 changed files with 30 additions and 150 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
* 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
@ -1083,49 +1083,19 @@ public class FileChannelImpl
// -- Locks --
// keeps track of locks on this file
private volatile FileLockTable fileLockTable;
// indicates if file locks are maintained system-wide (as per spec)
private static boolean isSharedFileLockTable;
// indicates if the disableSystemWideOverlappingFileLockCheck property
// has been checked
private static volatile boolean propertyChecked;
// The lock list in J2SE 1.4/5.0 was local to each FileChannel instance so
// the overlap check wasn't system wide when there were multiple channels to
// the same file. This property is used to get 1.4/5.0 behavior if desired.
private static boolean isSharedFileLockTable() {
if (!propertyChecked) {
synchronized (FileChannelImpl.class) {
if (!propertyChecked) {
String value = GetPropertyAction.privilegedGetProperty(
"sun.nio.ch.disableSystemWideOverlappingFileLockCheck");
isSharedFileLockTable = ((value == null) || value.equals("false"));
propertyChecked = true;
}
}
}
return isSharedFileLockTable;
}
private FileLockTable fileLockTable() throws IOException {
if (fileLockTable == null) {
synchronized (this) {
if (fileLockTable == null) {
if (isSharedFileLockTable()) {
int ti = threads.add();
try {
ensureOpen();
fileLockTable = FileLockTable.newSharedFileLockTable(this, fd);
} finally {
threads.remove(ti);
}
} else {
fileLockTable = new SimpleFileLockTable();
int ti = threads.add();
try {
ensureOpen();
fileLockTable = new FileLockTable(this, fd);
} finally {
threads.remove(ti);
}
}
}
@ -1229,59 +1199,6 @@ public class FileChannelImpl
fileLockTable.remove(fli);
}
// -- File lock support --
/**
* A simple file lock table that maintains a list of FileLocks obtained by a
* FileChannel. Use to get 1.4/5.0 behaviour.
*/
private static class SimpleFileLockTable extends FileLockTable {
// synchronize on list for access
private final List<FileLock> lockList = new ArrayList<FileLock>(2);
public SimpleFileLockTable() {
}
private void checkList(long position, long size)
throws OverlappingFileLockException
{
assert Thread.holdsLock(lockList);
for (FileLock fl: lockList) {
if (fl.overlaps(position, size)) {
throw new OverlappingFileLockException();
}
}
}
public void add(FileLock fl) throws OverlappingFileLockException {
synchronized (lockList) {
checkList(fl.position(), fl.size());
lockList.add(fl);
}
}
public void remove(FileLock fl) {
synchronized (lockList) {
lockList.remove(fl);
}
}
public List<FileLock> removeAll() {
synchronized(lockList) {
List<FileLock> result = new ArrayList<FileLock>(lockList);
lockList.clear();
return result;
}
}
public void replace(FileLock fl1, FileLock fl2) {
synchronized (lockList) {
lockList.remove(fl1);
lockList.add(fl2);
}
}
}
// -- Native methods --
// Creates a new mapping