< prev index next >

src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2000, 2017, 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
*** 1081,1134 **** }; } // -- 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(); - } } } } return fileLockTable; } --- 1081,1105 ---- }; } // -- Locks -- // keeps track of locks on this file private volatile FileLockTable fileLockTable; private FileLockTable fileLockTable() throws IOException { if (fileLockTable == null) { synchronized (this) { if (fileLockTable == null) { int ti = threads.add(); try { ensureOpen(); ! fileLockTable = ! FileLockTable.newFileLockTable(this, fd); } finally { threads.remove(ti); } } } } return fileLockTable; }
*** 1227,1289 **** } assert fileLockTable != null; 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 private native long map0(int prot, long position, long length) throws IOException; --- 1198,1207 ----
< prev index next >