8146800: Reorganize logging alias code

Logging alias code has been reorganized to use internal Unified Logging methods.

Reviewed-by: dholmes, hseigel, mlarsson, rprotacio
This commit is contained in:
Max Ockner 2016-01-13 14:56:17 -05:00
parent 380897b206
commit 45b28571f0
2 changed files with 38 additions and 32 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -33,6 +33,7 @@
#include "gc/shared/referenceProcessor.hpp" #include "gc/shared/referenceProcessor.hpp"
#include "gc/shared/taskqueue.hpp" #include "gc/shared/taskqueue.hpp"
#include "logging/log.hpp" #include "logging/log.hpp"
#include "logging/logTag.hpp"
#include "logging/logConfiguration.hpp" #include "logging/logConfiguration.hpp"
#include "memory/allocation.inline.hpp" #include "memory/allocation.inline.hpp"
#include "memory/universe.inline.hpp" #include "memory/universe.inline.hpp"
@ -399,14 +400,11 @@ static AliasedFlag const aliased_jvm_flags[] = {
{ NULL, NULL} { NULL, NULL}
}; };
static AliasedFlag const aliased_jvm_logging_flags[] = { static AliasedLoggingFlag const aliased_logging_flags[] = {
{ "-XX:+TraceClassResolution", "-Xlog:classresolve=info"}, { "TraceClassResolution", LogLevel::Info, true, LogTag::_classresolve },
{ "-XX:-TraceClassResolution", "-Xlog:classresolve=off"}, { "TraceExceptions", LogLevel::Info, true, LogTag::_exceptions },
{ "-XX:+TraceExceptions", "-Xlog:exceptions=info" }, { "TraceMonitorInflation", LogLevel::Debug, true, LogTag::_monitorinflation },
{ "-XX:-TraceExceptions", "-Xlog:exceptions=off" }, { NULL, LogLevel::Off, false, LogTag::__NO_TAG }
{ "-XX:+TraceMonitorInflation", "-Xlog:monitorinflation=debug" },
{ "-XX:-TraceMonitorInflation", "-Xlog:monitorinflation=off" },
{ NULL, NULL }
}; };
// Return true if "v" is less than "other", where "other" may be "undefined". // Return true if "v" is less than "other", where "other" may be "undefined".
@ -939,18 +937,15 @@ const char* Arguments::handle_aliases_and_deprecation(const char* arg, bool warn
return NULL; return NULL;
} }
// lookup_logging_aliases AliasedLoggingFlag Arguments::catch_logging_aliases(const char* name){
// Called from parse_each_vm_init_arg(). Should be called on -XX options before specific cases are checked. for (size_t i = 0; aliased_logging_flags[i].alias_name != NULL; i++) {
// If arg matches any aliased_jvm_logging_flags entry, look up the real name and copy it into buffer. const AliasedLoggingFlag& alf = aliased_logging_flags[i];
bool Arguments::lookup_logging_aliases(const char* arg, char* buffer) { if (strcmp(alf.alias_name, name) == 0) {
for (size_t i = 0; aliased_jvm_logging_flags[i].alias_name != NULL; i++) { return alf;
const AliasedFlag& flag_status = aliased_jvm_logging_flags[i];
if (strcmp(flag_status.alias_name, arg) == 0) {
strcpy(buffer, flag_status.real_name);
return true;
} }
} }
return false; AliasedLoggingFlag a = {NULL, LogLevel::Off, false, LogTag::__NO_TAG};
return a;
} }
bool Arguments::parse_argument(const char* arg, Flag::Flags origin) { bool Arguments::parse_argument(const char* arg, Flag::Flags origin) {
@ -962,8 +957,14 @@ bool Arguments::parse_argument(const char* arg, Flag::Flags origin) {
char dummy; char dummy;
const char* real_name; const char* real_name;
bool warn_if_deprecated = true; bool warn_if_deprecated = true;
AliasedLoggingFlag alf;
if (sscanf(arg, "-%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) { if (sscanf(arg, "-%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
alf = catch_logging_aliases(name);
if (alf.alias_name != NULL){
LogConfiguration::configure_stdout(LogLevel::Off, alf.exactMatch, alf.tag, LogTag::__NO_TAG);
return true;
}
real_name = handle_aliases_and_deprecation(name, warn_if_deprecated); real_name = handle_aliases_and_deprecation(name, warn_if_deprecated);
if (real_name == NULL) { if (real_name == NULL) {
return false; return false;
@ -971,6 +972,11 @@ bool Arguments::parse_argument(const char* arg, Flag::Flags origin) {
return set_bool_flag(real_name, false, origin); return set_bool_flag(real_name, false, origin);
} }
if (sscanf(arg, "+%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) { if (sscanf(arg, "+%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
alf = catch_logging_aliases(name);
if (alf.alias_name != NULL){
LogConfiguration::configure_stdout(alf.level, alf.exactMatch, alf.tag, LogTag::__NO_TAG);
return true;
}
real_name = handle_aliases_and_deprecation(name, warn_if_deprecated); real_name = handle_aliases_and_deprecation(name, warn_if_deprecated);
if (real_name == NULL) { if (real_name == NULL) {
return false; return false;
@ -2629,7 +2635,7 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
for (int index = 0; index < args->nOptions; index++) { for (int index = 0; index < args->nOptions; index++) {
bool is_absolute_path = false; // for -agentpath vs -agentlib bool is_absolute_path = false; // for -agentpath vs -agentlib
JavaVMOption* option = args->options + index; const JavaVMOption* option = args->options + index;
if (!match_option(option, "-Djava.class.path", &tail) && if (!match_option(option, "-Djava.class.path", &tail) &&
!match_option(option, "-Dsun.java.command", &tail) && !match_option(option, "-Dsun.java.command", &tail) &&
@ -2643,16 +2649,6 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
build_jvm_args(option->optionString); build_jvm_args(option->optionString);
} }
// char buffer to store looked up logging option.
char aliased_logging_option[256];
// Catch -XX options which are aliased to Unified logging commands.
if (match_option(option, "-XX:", &tail)) {
if (lookup_logging_aliases(option->optionString, aliased_logging_option)) {
option->optionString = aliased_logging_option;
}
}
// -verbose:[class/gc/jni] // -verbose:[class/gc/jni]
if (match_option(option, "-verbose", &tail)) { if (match_option(option, "-verbose", &tail)) {
if (!strcmp(tail, ":class") || !strcmp(tail, "")) { if (!strcmp(tail, ":class") || !strcmp(tail, "")) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,8 @@
#ifndef SHARE_VM_RUNTIME_ARGUMENTS_HPP #ifndef SHARE_VM_RUNTIME_ARGUMENTS_HPP
#define SHARE_VM_RUNTIME_ARGUMENTS_HPP #define SHARE_VM_RUNTIME_ARGUMENTS_HPP
#include "logging/logLevel.hpp"
#include "logging/logTag.hpp"
#include "runtime/java.hpp" #include "runtime/java.hpp"
#include "runtime/os.hpp" #include "runtime/os.hpp"
#include "runtime/perfData.hpp" #include "runtime/perfData.hpp"
@ -223,6 +225,14 @@ class AgentLibraryList VALUE_OBJ_CLASS_SPEC {
// Helper class for controlling the lifetime of JavaVMInitArgs objects. // Helper class for controlling the lifetime of JavaVMInitArgs objects.
class ScopedVMInitArgs; class ScopedVMInitArgs;
// Most logging functions require 5 tags. Some of them may be _NO_TAG.
typedef struct {
const char* alias_name;
LogLevelType level;
bool exactMatch;
LogTagType tag;
} AliasedLoggingFlag;
class Arguments : AllStatic { class Arguments : AllStatic {
friend class VMStructs; friend class VMStructs;
friend class JvmtiExport; friend class JvmtiExport;
@ -449,7 +459,7 @@ class Arguments : AllStatic {
// Return NULL if the arg has expired. // Return NULL if the arg has expired.
static const char* handle_aliases_and_deprecation(const char* arg, bool warn); static const char* handle_aliases_and_deprecation(const char* arg, bool warn);
static bool lookup_logging_aliases(const char* arg, char* buffer); static bool lookup_logging_aliases(const char* arg, char* buffer);
static AliasedLoggingFlag catch_logging_aliases(const char* name);
static short CompileOnlyClassesNum; static short CompileOnlyClassesNum;
static short CompileOnlyClassesMax; static short CompileOnlyClassesMax;
static char** CompileOnlyClasses; static char** CompileOnlyClasses;