Skip to content
Permalink
Browse files
8275436: [BACKOUT] JDK-8271949 dumppath in -XX:FlightRecorderOptions …
…does not affect

Reviewed-by: mgronlun
  • Loading branch information
Daniel D. Daugherty committed Oct 18, 2021
1 parent bad75e6 commit a03119ce1a34642565c669bd2471f52eec088b96
Showing 10 changed files with 32 additions and 167 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, 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
@@ -35,7 +35,6 @@
#include "jfr/recorder/repository/jfrRepository.hpp"
#include "jfr/recorder/repository/jfrChunkRotation.hpp"
#include "jfr/recorder/repository/jfrChunkWriter.hpp"
#include "jfr/recorder/repository/jfrEmergencyDump.hpp"
#include "jfr/recorder/service/jfrEventThrottler.hpp"
#include "jfr/recorder/service/jfrOptionSet.hpp"
#include "jfr/recorder/stacktrace/jfrStackTraceRepository.hpp"
@@ -316,16 +315,6 @@ JVM_ENTRY_NO_ENV(void, jfr_set_repository_location(JNIEnv* env, jobject repo, js
return JfrRepository::set_path(location, thread);
JVM_END

NO_TRANSITION(void, jfr_set_dump_path(JNIEnv* env, jobject jvm, jstring dumppath))
const char* dump_path = env->GetStringUTFChars(dumppath, NULL);
JfrEmergencyDump::set_dump_path(dump_path);
env->ReleaseStringUTFChars(dumppath, dump_path);
NO_TRANSITION_END

NO_TRANSITION(jstring, jfr_get_dump_path(JNIEnv* env, jobject jvm))
return env->NewStringUTF(JfrEmergencyDump::get_dump_path());
NO_TRANSITION_END

JVM_ENTRY_NO_ENV(void, jfr_uncaught_exception(JNIEnv* env, jobject jvm, jobject t, jthrowable throwable))
JfrJavaSupport::uncaught_exception(throwable, thread);
JVM_END
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, 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
@@ -113,10 +113,6 @@ jlong JNICALL jfr_type_id(JNIEnv* env, jobject jvm, jclass jc);

void JNICALL jfr_set_repository_location(JNIEnv* env, jobject repo, jstring location);

void JNICALL jfr_set_dump_path(JNIEnv* env, jobject jvm, jstring dumppath);

jstring JNICALL jfr_get_dump_path(JNIEnv* env, jobject jvm);

jobject JNICALL jfr_get_event_writer(JNIEnv* env, jclass cls);

jobject JNICALL jfr_new_event_writer(JNIEnv* env, jclass cls);
@@ -75,8 +75,6 @@ JfrJniMethodRegistration::JfrJniMethodRegistration(JNIEnv* env) {
(char*)"flush", (char*)"(Ljdk/jfr/internal/EventWriter;II)Z", (void*)jfr_event_writer_flush,
(char*)"flush", (char*)"()V", (void*)jfr_flush,
(char*)"setRepositoryLocation", (char*)"(Ljava/lang/String;)V", (void*)jfr_set_repository_location,
(char*)"setDumpPath", (char*)"(Ljava/lang/String;)V", (void*)jfr_set_dump_path,
(char*)"getDumpPath", (char*)"()Ljava/lang/String;", (void*)jfr_get_dump_path,
(char*)"abort", (char*)"(Ljava/lang/String;)V", (void*)jfr_abort,
(char*)"addStringConstant", (char*)"(JLjava/lang/String;)Z", (void*)jfr_add_string_constant,
(char*)"uncaughtException", (char*)"(Ljava/lang/Thread;Ljava/lang/Throwable;)V", (void*)jfr_uncaught_exception,
@@ -41,8 +41,6 @@
#include "utilities/growableArray.hpp"
#include "utilities/ostream.hpp"

char JfrEmergencyDump::_dump_path[JVM_MAXPATHLEN] = { 0 };

static const char vm_error_filename_fmt[] = "hs_err_pid%p.jfr";
static const char vm_oom_filename_fmt[] = "hs_oom_pid%p.jfr";
static const char vm_soe_filename_fmt[] = "hs_soe_pid%p.jfr";
@@ -68,17 +66,12 @@ static bool is_path_empty() {
}

// returns with an appended file separator (if successful)
static size_t get_dump_directory() {
const char* dump_path = JfrEmergencyDump::get_dump_path();
if (*dump_path == '\0') {
if (os::get_current_directory(_path_buffer, sizeof(_path_buffer)) == NULL) {
return 0;
}
} else {
strcpy(_path_buffer, dump_path);
static size_t get_current_directory() {
if (os::get_current_directory(_path_buffer, sizeof(_path_buffer)) == NULL) {
return 0;
}
const size_t path_len = strlen(_path_buffer);
const int result = jio_snprintf(_path_buffer + path_len,
const size_t cwd_len = strlen(_path_buffer);
const int result = jio_snprintf(_path_buffer + cwd_len,
sizeof(_path_buffer),
"%s",
os::file_separator());
@@ -112,7 +105,7 @@ static void close_emergency_dump_file() {
static const char* create_emergency_dump_path() {
assert(is_path_empty(), "invariant");

const size_t path_len = get_dump_directory();
const size_t path_len = get_current_directory();
if (path_len == 0) {
return NULL;
}
@@ -132,21 +125,12 @@ static const char* create_emergency_dump_path() {
return result ? _path_buffer : NULL;
}

bool JfrEmergencyDump::open_emergency_dump_file() {
static bool open_emergency_dump_file() {
if (is_emergency_dump_file_open()) {
// opened already
return true;
}

bool result = open_emergency_dump_fd(create_emergency_dump_path());
if (!result && *_dump_path != '\0') {
log_warning(jfr)("Unable to create an emergency dump file at the location set by dumppath=%s", _dump_path);
// Fallback. Try to create it in the current directory.
*_dump_path = '\0';
*_path_buffer = '\0';
result = open_emergency_dump_fd(create_emergency_dump_path());
}
return result;
return open_emergency_dump_fd(create_emergency_dump_path());
}

static void report(outputStream* st, bool emergency_file_opened, const char* repository_path) {
@@ -166,19 +150,6 @@ static void report(outputStream* st, bool emergency_file_opened, const char* rep
}
}

void JfrEmergencyDump::set_dump_path(const char* dump_path) {
if (dump_path != NULL) {
if (strlen(dump_path) < JVM_MAXPATHLEN) {
strncpy(_dump_path, dump_path, JVM_MAXPATHLEN);
_dump_path[JVM_MAXPATHLEN - 1] = '\0';
}
}
}

const char* JfrEmergencyDump::get_dump_path() {
return _dump_path;
}

void JfrEmergencyDump::on_vm_error_report(outputStream* st, const char* repository_path) {
assert(st != NULL, "invariant");
Thread* thread = Thread::current_or_null_safe();
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2020, 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,14 +32,7 @@
// Responsible for creating an hs_err<pid>.jfr file in exceptional shutdown situations (crash, OOM)
//
class JfrEmergencyDump : AllStatic {
private:
static char _dump_path[JVM_MAXPATHLEN];

static bool open_emergency_dump_file();

public:
static void set_dump_path(const char* dump_path);
static const char* get_dump_path();
static const char* chunk_path(const char* repository_path);
static void on_vm_error(const char* repository_path);
static void on_vm_error_report(outputStream* st, const char* repository_path);
@@ -163,7 +163,6 @@ bool JfrOptionSet::allow_event_retransforms() {

// default options for the dcmd parser
const char* const default_repository = NULL;
const char* const default_dumppath = NULL;
const char* const default_global_buffer_size = "512k";
const char* const default_num_global_buffers = "20";
const char* const default_memory_size = "10m";
@@ -183,13 +182,6 @@ static DCmdArgument<char*> _dcmd_repository(
false,
default_repository);

static DCmdArgument<char*> _dcmd_dumppath(
"dumppath",
"Path to emergency dump",
"STRING",
false,
default_dumppath);

static DCmdArgument<MemorySizeArgument> _dcmd_threadbuffersize(
"threadbuffersize",
"Thread buffer size",
@@ -266,7 +258,6 @@ static DCmdParser _parser;

static void register_parser_options() {
_parser.add_dcmd_option(&_dcmd_repository);
_parser.add_dcmd_option(&_dcmd_dumppath);
_parser.add_dcmd_option(&_dcmd_threadbuffersize);
_parser.add_dcmd_option(&_dcmd_memorysize);
_parser.add_dcmd_option(&_dcmd_globalbuffersize);
@@ -355,18 +346,6 @@ bool JfrOptionSet::configure(TRAPS) {
configure._repository_path.set_value(repo_copy);
}

configure._dump_path.set_is_set(_dcmd_dumppath.is_set());
char* dumppath = _dcmd_dumppath.value();
if (dumppath != NULL) {
const size_t len = strlen(dumppath);
char* dumppath_copy = JfrCHeapObj::new_array<char>(len + 1);
if (NULL == dumppath_copy) {
return false;
}
strncpy(dumppath_copy, dumppath, len + 1);
configure._dump_path.set_value(dumppath_copy);
}

configure._stack_depth.set_is_set(_dcmd_stackdepth.is_set());
configure._stack_depth.set_value(_dcmd_stackdepth.value());

@@ -473,26 +473,13 @@ public boolean hasNativeJFR() {
public native void flush();

/**
* Sets the location of the disk repository.
* Sets the location of the disk repository, to be used at an emergency
* dump.
*
* @param dirText
*/
public native void setRepositoryLocation(String dirText);

/**
* Sets the path to emergency dump.
*
* @param dumpPathText
*/
public native void setDumpPath(String dumpPathText);

/**
* Gets the path to emergency dump.
*
* @return The path to emergency dump.
*/
public native String getDumpPath();

/**
* Access to VM termination support.
*
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2021, 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
@@ -25,16 +25,9 @@

package jdk.jfr.internal;

import java.io.IOException;

import jdk.jfr.internal.LogLevel;
import jdk.jfr.internal.LogTag;
import jdk.jfr.internal.Logger;
import jdk.jfr.internal.SecuritySupport.SafePath;
import jdk.internal.misc.Unsafe;

import static java.nio.file.LinkOption.*;

/**
* Options that control Flight Recorder.
*
@@ -55,7 +48,7 @@ public final class Options {
private static final int DEFAULT_STACK_DEPTH = 64;
private static final boolean DEFAULT_SAMPLE_THREADS = true;
private static final long DEFAULT_MAX_CHUNK_SIZE = 12 * 1024 * 1024;
private static final SafePath DEFAULT_DUMP_PATH = new SafePath(".");
private static final SafePath DEFAULT_DUMP_PATH = SecuritySupport.USER_HOME;

private static long memorySize;
private static long globalBufferSize;
@@ -64,6 +57,7 @@ public final class Options {
private static int stackDepth;
private static boolean sampleThreads;
private static long maxChunkSize;
private static SafePath dumpPath;

static {
final long pageSize = Unsafe.getUnsafe().pageSize();
@@ -120,23 +114,11 @@ public static synchronized void setGlobalBufferSize(long globalBufsize) {
}

public static synchronized void setDumpPath(SafePath path) {
if (path.toFile().canWrite()) {
try {
jvm.setDumpPath(path.toPath().toRealPath(NOFOLLOW_LINKS).toString());
} catch (IOException e) {
if (Logger.shouldLog(LogTag.JFR_SYSTEM_SETTING, LogLevel.WARN)) {
Logger.log(LogTag.JFR_SYSTEM_SETTING, LogLevel.WARN, "Error occurred in path resolution: " + e.toString());
}
}
} else {
if (Logger.shouldLog(LogTag.JFR_SYSTEM_SETTING, LogLevel.WARN)) {
Logger.log(LogTag.JFR_SYSTEM_SETTING, LogLevel.WARN, "Cannot write JFR emergency dump to " + path.toString());
}
}
dumpPath = path;
}

public static synchronized SafePath getDumpPath() {
return new SafePath(jvm.getDumpPath());
return dumpPath;
}

public static synchronized void setStackDepth(Integer stackTraceDepth) {
@@ -77,6 +77,7 @@ public final class SecuritySupport {
private static final Module JFR_MODULE = Event.class.getModule();
public static final SafePath JFC_DIRECTORY = getPathInProperty("java.home", "lib/jfr");
public static final FileAccess PRIVILEGED = new Privileged();
static final SafePath USER_HOME = getPathInProperty("user.home", null);
static final SafePath JAVA_IO_TMPDIR = getPathInProperty("java.io.tmpdir", null);

static {

1 comment on commit a03119c

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on a03119c Oct 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.