mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8195059: Update java.net Socket and DatagramSocket implementations to use Cleaner
Reviewed-by: chegar, plevart
This commit is contained in:
parent
89c2e03b1d
commit
0b8689b331
15 changed files with 1113 additions and 60 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1995, 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
|
||||
|
@ -91,6 +91,14 @@ public final class FileDescriptor {
|
|||
fdo.registerCleanup();
|
||||
}
|
||||
|
||||
public void registerCleanup(FileDescriptor fdo, PhantomCleanable<Object> cleanup) {
|
||||
fdo.registerCleanup(cleanup);
|
||||
}
|
||||
|
||||
public void unregisterCleanup(FileDescriptor fdo) {
|
||||
fdo.unregisterCleanup();
|
||||
}
|
||||
|
||||
public void setHandle(FileDescriptor fdo, long handle) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
@ -105,7 +113,7 @@ public final class FileDescriptor {
|
|||
/**
|
||||
* Cleanup in case FileDescriptor is not explicitly closed.
|
||||
*/
|
||||
private FDCleanup cleanup;
|
||||
private PhantomCleanable<Object> cleanup;
|
||||
|
||||
/**
|
||||
* Constructs an (invalid) FileDescriptor
|
||||
|
@ -206,16 +214,44 @@ public final class FileDescriptor {
|
|||
}
|
||||
|
||||
/**
|
||||
* Register a cleanup for the current raw fd.
|
||||
* Register a cleanup for the current handle.
|
||||
* Used directly in java.io and indirectly via fdAccess.
|
||||
* The cleanup should be registered after the fd is set in the FileDescriptor.
|
||||
* The cleanup should be registered after the handle is set in the FileDescriptor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
synchronized void registerCleanup() {
|
||||
void registerCleanup() {
|
||||
registerCleanup(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a cleanup for the current handle.
|
||||
* Used directly in java.io and indirectly via fdAccess.
|
||||
* The cleanup should be registered after the handle is set in the FileDescriptor.
|
||||
* @param newCleanable a PhantomCleanable to register
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
synchronized void registerCleanup(PhantomCleanable<Object> newCleanable) {
|
||||
if (cleanup != null) {
|
||||
cleanup.clear();
|
||||
}
|
||||
cleanup = FDCleanup.create(this);
|
||||
cleanup = (newCleanable == null) ? FDCleanup.create(this) : newCleanable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a cleanup for the current raw fd.
|
||||
* Used directly in java.io and indirectly via fdAccess.
|
||||
* Normally {@link #close()} should be used except in cases where
|
||||
* it is certain the caller will close the raw fd and the cleanup
|
||||
* must not close the raw fd. {@link #unregisterCleanup()} must be
|
||||
* called before the raw fd is closed to prevent a race that makes
|
||||
* it possible for the fd to be reallocated to another use and later
|
||||
* the cleanup might be invoked.
|
||||
*/
|
||||
synchronized void unregisterCleanup() {
|
||||
if (cleanup != null) {
|
||||
cleanup.clear();
|
||||
}
|
||||
cleanup = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 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
|
||||
|
@ -27,6 +27,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "net_util.h"
|
||||
#include "java_net_SocketCleanable.h"
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_java_net_AbstractPlainSocketImpl_isReusePortAvailable0(JNIEnv* env, jclass c1)
|
||||
|
@ -45,3 +46,15 @@ Java_jdk_net_Sockets_isReusePortAvailable0(JNIEnv* env, jclass c1)
|
|||
{
|
||||
return (reuseport_available()) ? JNI_TRUE : JNI_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: java_net_SocketCleanable
|
||||
* Method: cleanupClose0
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_java_net_SocketCleanable_cleanupClose0(JNIEnv *env, jclass c1, jint fd)
|
||||
{
|
||||
NET_SocketClose(fd);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue