author | ihse |
Tue, 13 Feb 2018 10:37:33 +0100 | |
branch | ihse-remove-mapfiles-branch |
changeset 56106 | 40e61db323c2 |
parent 47765 | b7c7428eaab9 |
child 55656 | 1346086863a3 |
permissions | -rw-r--r-- |
33097 | 1 |
/* |
46560
388aa8d67c80
8181449: Fix debug.hpp / globalDefinitions.hpp dependency inversion
kbarrett
parents:
42066
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
33097 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
#include "precompiled.hpp" |
|
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47216
diff
changeset
|
25 |
#include "jvm.h" |
33097 | 26 |
#include "logging/logConfiguration.hpp" |
27 |
#include "logging/logDecorations.hpp" |
|
28 |
#include "runtime/os.inline.hpp" |
|
29 |
#include "runtime/thread.inline.hpp" |
|
30 |
#include "services/management.hpp" |
|
31 |
||
32 |
jlong LogDecorations::_vm_start_time_millis = 0; |
|
36174 | 33 |
const char* LogDecorations::_host_name = ""; |
33097 | 34 |
|
35 |
LogDecorations::LogDecorations(LogLevelType level, const LogTagSet &tagset, const LogDecorators &decorators) |
|
38263
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
36174
diff
changeset
|
36 |
: _level(level), _tagset(tagset), _millis(-1) { |
33097 | 37 |
create_decorations(decorators); |
38 |
} |
|
39 |
||
36174 | 40 |
void LogDecorations::initialize(jlong vm_start_time) { |
41 |
char buffer[1024]; |
|
42 |
if (os::get_host_name(buffer, sizeof(buffer))){ |
|
43 |
_host_name = os::strdup_check_oom(buffer); |
|
44 |
} |
|
45 |
_vm_start_time_millis = vm_start_time; |
|
46 |
} |
|
47 |
||
33097 | 48 |
void LogDecorations::create_decorations(const LogDecorators &decorators) { |
49 |
char* position = _decorations_buffer; |
|
50 |
#define DECORATOR(full_name, abbr) \ |
|
51 |
if (decorators.is_decorator(LogDecorators::full_name##_decorator)) { \ |
|
52 |
_decoration_offset[LogDecorators::full_name##_decorator] = position; \ |
|
53 |
position = create_##full_name##_decoration(position) + 1; \ |
|
54 |
} |
|
55 |
DECORATOR_LIST |
|
56 |
#undef DECORATOR |
|
57 |
} |
|
58 |
||
59 |
jlong LogDecorations::java_millis() { |
|
60 |
if (_millis < 0) { |
|
61 |
_millis = os::javaTimeMillis(); |
|
62 |
} |
|
63 |
return _millis; |
|
64 |
} |
|
65 |
||
66 |
#define ASSERT_AND_RETURN(written, pos) \ |
|
67 |
assert(written >= 0, "Decorations buffer overflow"); \ |
|
68 |
return pos + written; |
|
69 |
||
70 |
char* LogDecorations::create_time_decoration(char* pos) { |
|
71 |
char* buf = os::iso8601_time(pos, 29); |
|
72 |
int written = buf == NULL ? -1 : 29; |
|
73 |
ASSERT_AND_RETURN(written, pos) |
|
74 |
} |
|
75 |
||
42066 | 76 |
char* LogDecorations::create_utctime_decoration(char* pos) { |
77 |
char* buf = os::iso8601_time(pos, 29, true); |
|
78 |
int written = buf == NULL ? -1 : 29; |
|
79 |
ASSERT_AND_RETURN(written, pos) |
|
80 |
} |
|
81 |
||
33097 | 82 |
char * LogDecorations::create_uptime_decoration(char* pos) { |
83 |
int written = jio_snprintf(pos, DecorationsBufferSize - (pos - _decorations_buffer), "%.3fs", os::elapsedTime()); |
|
84 |
ASSERT_AND_RETURN(written, pos) |
|
85 |
} |
|
86 |
||
87 |
char * LogDecorations::create_timemillis_decoration(char* pos) { |
|
88 |
int written = jio_snprintf(pos, DecorationsBufferSize - (pos - _decorations_buffer), INT64_FORMAT "ms", java_millis()); |
|
89 |
ASSERT_AND_RETURN(written, pos) |
|
90 |
} |
|
91 |
||
92 |
char * LogDecorations::create_uptimemillis_decoration(char* pos) { |
|
93 |
int written = jio_snprintf(pos, DecorationsBufferSize - (pos - _decorations_buffer), |
|
94 |
INT64_FORMAT "ms", java_millis() - _vm_start_time_millis); |
|
95 |
ASSERT_AND_RETURN(written, pos) |
|
96 |
} |
|
97 |
||
98 |
char * LogDecorations::create_timenanos_decoration(char* pos) { |
|
99 |
int written = jio_snprintf(pos, DecorationsBufferSize - (pos - _decorations_buffer), INT64_FORMAT "ns", os::javaTimeNanos()); |
|
100 |
ASSERT_AND_RETURN(written, pos) |
|
101 |
} |
|
102 |
||
103 |
char * LogDecorations::create_uptimenanos_decoration(char* pos) { |
|
104 |
int written = jio_snprintf(pos, DecorationsBufferSize - (pos - _decorations_buffer), INT64_FORMAT "ns", os::elapsed_counter()); |
|
105 |
ASSERT_AND_RETURN(written, pos) |
|
106 |
} |
|
107 |
||
108 |
char * LogDecorations::create_pid_decoration(char* pos) { |
|
109 |
int written = jio_snprintf(pos, DecorationsBufferSize - (pos - _decorations_buffer), "%d", os::current_process_id()); |
|
110 |
ASSERT_AND_RETURN(written, pos) |
|
111 |
} |
|
112 |
||
113 |
char * LogDecorations::create_tid_decoration(char* pos) { |
|
114 |
int written = jio_snprintf(pos, DecorationsBufferSize - (pos - _decorations_buffer), |
|
34646
e2442a5c90e4
8144702: Using tid decorator in Unified Logging may crash VM
stuefe
parents:
33097
diff
changeset
|
115 |
INTX_FORMAT, os::current_thread_id()); |
33097 | 116 |
ASSERT_AND_RETURN(written, pos) |
117 |
} |
|
118 |
||
119 |
char* LogDecorations::create_level_decoration(char* pos) { |
|
38263
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
36174
diff
changeset
|
120 |
// Avoid generating the level decoration because it may change. |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
36174
diff
changeset
|
121 |
// The decoration() method has a special case for level decorations. |
a7488329ad27
8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents:
36174
diff
changeset
|
122 |
return pos; |
33097 | 123 |
} |
124 |
||
125 |
char* LogDecorations::create_tags_decoration(char* pos) { |
|
126 |
int written = _tagset.label(pos, DecorationsBufferSize - (pos - _decorations_buffer)); |
|
127 |
ASSERT_AND_RETURN(written, pos) |
|
128 |
} |
|
36174 | 129 |
|
130 |
char* LogDecorations::create_hostname_decoration(char* pos) { |
|
131 |
int written = jio_snprintf(pos, DecorationsBufferSize - (pos - _decorations_buffer), "%s", _host_name); |
|
132 |
ASSERT_AND_RETURN(written, pos) |
|
133 |
} |
|
134 |