提交 c704b758 编写于 作者: C coffeys

7047325: Internal API to improve management of direct buffers

Reviewed-by: alanb, mduigou
上级 3633c027
#
# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 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
......@@ -27,8 +27,13 @@ BUILDDIR = ../..
PRODUCT = oracle
include $(BUILDDIR)/common/Defs.gmk
SUBDIRS = net
include $(BUILDDIR)/common/Subdirs.gmk
#
# Files to compile
#
AUTO_FILES_JAVA_DIRS = com/oracle
#
# Rules
#
include $(BUILDDIR)/common/Classes.gmk
all build clean clobber::
$(SUBDIRS-loop)
#
# Copyright (c) 2010, 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
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
BUILDDIR = ../../..
PRODUCT = oracle
include $(BUILDDIR)/common/Defs.gmk
#
# Files to compile
#
AUTO_FILES_JAVA_DIRS = com/oracle/net
#
# Rules
#
include $(BUILDDIR)/common/Classes.gmk
......@@ -60,7 +60,8 @@ EXCLUDE_PROPWARN_PKGS = com.sun.java.swing.plaf.windows \
# with a new module system (being discussed for JDK 8).
#
EXPORTED_PRIVATE_PKGS = com.sun.servicetag \
com.oracle.net
com.oracle.net \
com.oracle.nio
# 64-bit solaris has a few special cases. We define the variable
# SOLARIS64 for use in this Makefile to easily test those cases
......
/*
* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2011, 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
......@@ -699,6 +699,14 @@ class Bits { // package-private
}
};
}
@Override
public ByteBuffer newDirectByteBuffer(long addr, int cap, Object ob) {
return new DirectByteBuffer(addr, cap, ob);
}
@Override
public void truncate(Buffer buf) {
buf.truncate();
}
});
}
......
/*
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2011, 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
......@@ -543,6 +543,13 @@ public abstract class Buffer {
return mark;
}
final void truncate() { // package-private
mark = -1;
position = 0;
limit = 0;
capacity = 0;
}
final void discardMark() { // package-private
mark = -1;
}
......
/*
* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2011, 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
......@@ -58,12 +58,13 @@ class Direct$Type$Buffer$RW$$BO$
// NOTE: moved up to Buffer.java for speed in JNI GetDirectBufferAddress
// protected long address;
// If this buffer is a view of another buffer then we keep a reference to
// that buffer so that its memory isn't freed before we're done with it
protected Object viewedBuffer = null;
// An object attached to this buffer. If this buffer is a view of another
// buffer then we use this field to keep a reference to that buffer to
// ensure that its memory isn't freed before we are done with it.
private final Object att;
public Object viewedBuffer() {
return viewedBuffer;
public Object attachment() {
return att;
}
#if[byte]
......@@ -136,6 +137,7 @@ class Direct$Type$Buffer$RW$$BO$
address = base;
}
cleaner = Cleaner.create(this, new Deallocator(base, size, cap));
att = null;
#else[rw]
super(cap);
#end[rw]
......@@ -143,12 +145,24 @@ class Direct$Type$Buffer$RW$$BO$
#if[rw]
// Invoked to construct a direct ByteBuffer referring to the block of
// memory. A given arbitrary object may also be attached to the buffer.
//
Direct$Type$Buffer(long addr, int cap, Object ob) {
super(-1, 0, cap, cap);
address = addr;
cleaner = null;
att = ob;
}
// Invoked only by JNI: NewDirectByteBuffer(void*, long)
//
private Direct$Type$Buffer(long addr, int cap) {
super(-1, 0, cap, cap);
address = addr;
cleaner = null;
att = null;
}
#end[rw]
......@@ -162,8 +176,8 @@ class Direct$Type$Buffer$RW$$BO$
#if[rw]
super(-1, 0, cap, cap, fd);
address = addr;
viewedBuffer = null;
cleaner = Cleaner.create(this, unmapper);
att = null;
#else[rw]
super(cap, addr, fd, unmapper);
#end[rw]
......@@ -180,10 +194,10 @@ class Direct$Type$Buffer$RW$$BO$
#if[rw]
super(mark, pos, lim, cap);
address = db.address() + off;
viewedBuffer = db;
#if[byte]
cleaner = null;
#end[byte]
att = db;
#else[rw]
super(db, mark, pos, lim, cap, off);
#end[rw]
......
/*
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2011, 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
......@@ -25,6 +25,9 @@
package sun.misc;
import java.nio.Buffer;
import java.nio.ByteBuffer;
public interface JavaNioAccess {
/**
* Provides access to information on buffer usage.
......@@ -36,4 +39,18 @@ public interface JavaNioAccess {
long getMemoryUsed();
}
BufferPool getDirectBufferPool();
/**
* Constructs a direct ByteBuffer referring to the block of memory starting
* at the given memory address and and extending {@code cap} bytes.
* The {@code ob} parameter is an arbitrary object that is attached
* to the resulting buffer.
*/
ByteBuffer newDirectByteBuffer(long addr, int cap, Object ob);
/**
* Truncates a buffer by changing its capacity to 0.
*/
void truncate(Buffer buf);
}
/*
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2011, 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
......@@ -32,7 +32,7 @@ public interface DirectBuffer {
public long address();
public Object viewedBuffer();
public Object attachment();
public Cleaner cleaner();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册