Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8225690: Multiple AttachListener threads can be created

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2018 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -71,17 +71,7 @@ class AixAttachListener: AllStatic {
// the file descriptor for the listening socket
static int _listener;

static void set_path(char* path) {
if (path == NULL) {
_has_path = false;
} else {
strncpy(_path, path, UNIX_PATH_MAX);
_path[UNIX_PATH_MAX-1] = '\0';
_has_path = true;
}
}

static void set_listener(int s) { _listener = s; }
static bool _atexit_registered;

// reads a request from the given connected socket
static AixAttachOperation* read_request(int s);
@@ -94,6 +84,19 @@ class AixAttachListener: AllStatic {
ATTACH_ERROR_BADVERSION = 101 // error codes
};

static void set_path(char* path) {
if (path == NULL) {
_path[0] = '\0';
_has_path = false;
} else {
strncpy(_path, path, UNIX_PATH_MAX);
_path[UNIX_PATH_MAX-1] = '\0';
_has_path = true;
}
}

static void set_listener(int s) { _listener = s; }

// initialize the listener, returns 0 if okay
static int init();

@@ -130,6 +133,7 @@ class AixAttachOperation: public AttachOperation {
char AixAttachListener::_path[UNIX_PATH_MAX];
bool AixAttachListener::_has_path;
int AixAttachListener::_listener = -1;
bool AixAttachListener::_atexit_registered = false;
// Shutdown marker to prevent accept blocking during clean-up
bool AixAttachListener::_shutdown = false;

@@ -177,17 +181,15 @@ class ArgumentIterator : public StackObj {
// should be sufficient for cleanup.
extern "C" {
static void listener_cleanup() {
static int cleanup_done;
if (!cleanup_done) {
cleanup_done = 1;
AixAttachListener::set_shutdown(true);
int s = AixAttachListener::listener();
if (s != -1) {
::shutdown(s, 2);
}
if (AixAttachListener::has_path()) {
::unlink(AixAttachListener::path());
}
AixAttachListener::set_shutdown(true);
int s = AixAttachListener::listener();
if (s != -1) {
AixAttachListener::set_listener(-1);
::shutdown(s, 2);
}
if (AixAttachListener::has_path()) {
::unlink(AixAttachListener::path());
AixAttachListener::set_path(NULL);
}
}
}
@@ -200,7 +202,10 @@ int AixAttachListener::init() {
int listener; // listener socket (file descriptor)

// register function to cleanup
::atexit(listener_cleanup);
if (!_atexit_registered) {
_atexit_registered = true;
::atexit(listener_cleanup);
}

int n = snprintf(path, UNIX_PATH_MAX, "%s/.java_pid%d",
os::get_temp_directory(), os::current_process_id());
@@ -515,6 +520,26 @@ int AttachListener::pd_init() {
return ret_code;
}

bool AttachListener::check_socket_file() {
int ret;
struct stat64 st;
ret = stat64(AixAttachListener::path(), &st);
if (ret == -1) { // need to restart attach listener.
log_debug(attach)("Socket file %s does not exist - Restart Attach Listener",
AixAttachListener::path());

listener_cleanup();

// wait to terminate current attach listener instance...
while (AttachListener::transit_state(AL_INITIALIZING,
AL_NOT_INITIALIZED) != AL_NOT_INITIALIZED) {
os::naked_yield();
}
return is_init_trigger();
}
return false;
}

// Attach Listener is started lazily except in the case when
// +ReduseSignalUsage is used
bool AttachListener::init_at_startup() {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2019, 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
@@ -68,17 +68,7 @@ class BsdAttachListener: AllStatic {
// the file descriptor for the listening socket
static int _listener;

static void set_path(char* path) {
if (path == NULL) {
_has_path = false;
} else {
strncpy(_path, path, UNIX_PATH_MAX);
_path[UNIX_PATH_MAX-1] = '\0';
_has_path = true;
}
}

static void set_listener(int s) { _listener = s; }
static bool _atexit_registered;

// reads a request from the given connected socket
static BsdAttachOperation* read_request(int s);
@@ -91,6 +81,19 @@ class BsdAttachListener: AllStatic {
ATTACH_ERROR_BADVERSION = 101 // error codes
};

static void set_path(char* path) {
if (path == NULL) {
_path[0] = '\0';
_has_path = false;
} else {
strncpy(_path, path, UNIX_PATH_MAX);
_path[UNIX_PATH_MAX-1] = '\0';
_has_path = true;
}
}

static void set_listener(int s) { _listener = s; }

// initialize the listener, returns 0 if okay
static int init();

@@ -124,6 +127,7 @@ class BsdAttachOperation: public AttachOperation {
char BsdAttachListener::_path[UNIX_PATH_MAX];
bool BsdAttachListener::_has_path;
int BsdAttachListener::_listener = -1;
bool BsdAttachListener::_atexit_registered = false;

// Supporting class to help split a buffer into individual components
class ArgumentIterator : public StackObj {
@@ -158,16 +162,15 @@ class ArgumentIterator : public StackObj {
// bound too.
extern "C" {
static void listener_cleanup() {
static int cleanup_done;
if (!cleanup_done) {
cleanup_done = 1;
int s = BsdAttachListener::listener();
if (s != -1) {
::close(s);
}
if (BsdAttachListener::has_path()) {
::unlink(BsdAttachListener::path());
}
int s = BsdAttachListener::listener();
if (s != -1) {
BsdAttachListener::set_listener(-1);
::shutdown(s, SHUT_RDWR);
::close(s);
}
if (BsdAttachListener::has_path()) {
::unlink(BsdAttachListener::path());
BsdAttachListener::set_path(NULL);
}
}
}
@@ -180,7 +183,10 @@ int BsdAttachListener::init() {
int listener; // listener socket (file descriptor)

// register function to cleanup
::atexit(listener_cleanup);
if (!_atexit_registered) {
_atexit_registered = true;
::atexit(listener_cleanup);
}

int n = snprintf(path, UNIX_PATH_MAX, "%s/.java_pid%d",
os::get_temp_directory(), os::current_process_id());
@@ -485,6 +491,28 @@ int AttachListener::pd_init() {
return ret_code;
}

bool AttachListener::check_socket_file() {
int ret;
struct stat st;
ret = stat(BsdAttachListener::path(), &st);
if (ret == -1) { // need to restart attach listener.
log_debug(attach)("Socket file %s does not exist - Restart Attach Listener",
BsdAttachListener::path());

listener_cleanup();

// wait to terminate current attach listener instance...

while (AttachListener::transit_state(AL_INITIALIZING,

AL_NOT_INITIALIZED) != AL_NOT_INITIALIZED) {
os::naked_yield();
}
return is_init_trigger();
}
return false;
}

// Attach Listener is started lazily except in the case when
// +ReduseSignalUsage is used
bool AttachListener::init_at_startup() {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2019, 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
@@ -69,17 +69,7 @@ class LinuxAttachListener: AllStatic {
// the file descriptor for the listening socket
static int _listener;

static void set_path(char* path) {
if (path == NULL) {
_has_path = false;
} else {
strncpy(_path, path, UNIX_PATH_MAX);
_path[UNIX_PATH_MAX-1] = '\0';
_has_path = true;
}
}

static void set_listener(int s) { _listener = s; }
static bool _atexit_registered;

// reads a request from the given connected socket
static LinuxAttachOperation* read_request(int s);
@@ -92,6 +82,19 @@ class LinuxAttachListener: AllStatic {
ATTACH_ERROR_BADVERSION = 101 // error codes
};

static void set_path(char* path) {
if (path == NULL) {
_path[0] = '\0';
_has_path = false;
} else {
strncpy(_path, path, UNIX_PATH_MAX);
_path[UNIX_PATH_MAX-1] = '\0';
_has_path = true;
}
}

static void set_listener(int s) { _listener = s; }

// initialize the listener, returns 0 if okay
static int init();

@@ -125,6 +128,7 @@ class LinuxAttachOperation: public AttachOperation {
char LinuxAttachListener::_path[UNIX_PATH_MAX];
bool LinuxAttachListener::_has_path;
int LinuxAttachListener::_listener = -1;
bool LinuxAttachListener::_atexit_registered = false;

// Supporting class to help split a buffer into individual components
class ArgumentIterator : public StackObj {
@@ -159,16 +163,15 @@ class ArgumentIterator : public StackObj {
// bound too.
extern "C" {
static void listener_cleanup() {
static int cleanup_done;
if (!cleanup_done) {
cleanup_done = 1;
int s = LinuxAttachListener::listener();
if (s != -1) {
::close(s);
}
if (LinuxAttachListener::has_path()) {
::unlink(LinuxAttachListener::path());
}
int s = LinuxAttachListener::listener();
if (s != -1) {
LinuxAttachListener::set_listener(-1);
::shutdown(s, SHUT_RDWR);
::close(s);
}
if (LinuxAttachListener::has_path()) {
::unlink(LinuxAttachListener::path());
LinuxAttachListener::set_path(NULL);
}
}
}
@@ -181,7 +184,10 @@ int LinuxAttachListener::init() {
int listener; // listener socket (file descriptor)

// register function to cleanup
::atexit(listener_cleanup);
if (!_atexit_registered) {
_atexit_registered = true;
::atexit(listener_cleanup);
}

int n = snprintf(path, UNIX_PATH_MAX, "%s/.java_pid%d",
os::get_temp_directory(), os::current_process_id());
@@ -485,6 +491,26 @@ int AttachListener::pd_init() {
return ret_code;
}

bool AttachListener::check_socket_file() {
int ret;
struct stat64 st;
ret = stat64(LinuxAttachListener::path(), &st);
if (ret == -1) { // need to restart attach listener.
log_debug(attach)("Socket file %s does not exist - Restart Attach Listener",
LinuxAttachListener::path());

listener_cleanup();

// wait to terminate current attach listener instance...
while (AttachListener::transit_state(AL_INITIALIZING,
AL_NOT_INITIALIZED) != AL_NOT_INITIALIZED) {
os::naked_yield();
}
return is_init_trigger();
}
return false;
}

// Attach Listener is started lazily except in the case when
// +ReduseSignalUsage is used
bool AttachListener::init_at_startup() {