author | hseigel |
Mon, 23 Oct 2017 10:42:26 -0400 | |
changeset 47684 | c3c04b6e14f8 |
parent 47216 | 71c04702a3d5 |
child 48157 | 7c4d43c26352 |
permissions | -rw-r--r-- |
26135 | 1 |
/* |
46365
d79745f72ae6
8171042: The 'REQUIRED' type in sharedPathsMiscInfo.hpp is not used and should be removed.
jiangli
parents:
42876
diff
changeset
|
2 |
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. |
26135 | 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 |
||
25 |
#include "precompiled.hpp" |
|
26 |
#include "classfile/classLoader.hpp" |
|
27 |
#include "classfile/classLoaderData.inline.hpp" |
|
28 |
#include "classfile/sharedPathsMiscInfo.hpp" |
|
36364
5971776598e5
8150103: Convert TraceClassPaths to Unified Logging
mockner
parents:
34287
diff
changeset
|
29 |
#include "logging/log.hpp" |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46365
diff
changeset
|
30 |
#include "logging/logStream.hpp" |
26135 | 31 |
#include "memory/allocation.inline.hpp" |
32 |
#include "memory/metaspaceShared.hpp" |
|
37248 | 33 |
#include "memory/resourceArea.hpp" |
26135 | 34 |
#include "runtime/arguments.hpp" |
36364
5971776598e5
8150103: Convert TraceClassPaths to Unified Logging
mockner
parents:
34287
diff
changeset
|
35 |
#include "utilities/ostream.hpp" |
26135 | 36 |
|
37 |
void SharedPathsMiscInfo::add_path(const char* path, int type) { |
|
38151
fffedc5e5cf8
8154110: Update class* and safepoint* logging subsystems
mockner
parents:
37248
diff
changeset
|
38 |
log_info(class, path)("type=%s ", type_name(type)); |
36364
5971776598e5
8150103: Convert TraceClassPaths to Unified Logging
mockner
parents:
34287
diff
changeset
|
39 |
ClassLoader::trace_class_path("add misc shared path ", path); |
26135 | 40 |
write(path, strlen(path) + 1); |
41 |
write_jint(jint(type)); |
|
42 |
} |
|
43 |
||
44 |
void SharedPathsMiscInfo::ensure_size(size_t needed_bytes) { |
|
45 |
assert(_allocated, "cannot modify buffer during validation."); |
|
46 |
int used = get_used_bytes(); |
|
47 |
int target = used + int(needed_bytes); |
|
48 |
if (target > _buf_size) { |
|
49 |
_buf_size = _buf_size * 2 + (int)needed_bytes; |
|
50 |
_buf_start = REALLOC_C_HEAP_ARRAY(char, _buf_start, _buf_size, mtClass); |
|
51 |
_cur_ptr = _buf_start + used; |
|
52 |
_end_ptr = _buf_start + _buf_size; |
|
53 |
} |
|
54 |
} |
|
55 |
||
56 |
void SharedPathsMiscInfo::write(const void* ptr, size_t size) { |
|
57 |
ensure_size(size); |
|
58 |
memcpy(_cur_ptr, ptr, size); |
|
59 |
_cur_ptr += size; |
|
60 |
} |
|
61 |
||
62 |
bool SharedPathsMiscInfo::read(void* ptr, size_t size) { |
|
63 |
if (_cur_ptr + size <= _end_ptr) { |
|
64 |
memcpy(ptr, _cur_ptr, size); |
|
65 |
_cur_ptr += size; |
|
66 |
return true; |
|
67 |
} |
|
68 |
return false; |
|
69 |
} |
|
70 |
||
71 |
bool SharedPathsMiscInfo::fail(const char* msg, const char* name) { |
|
36364
5971776598e5
8150103: Convert TraceClassPaths to Unified Logging
mockner
parents:
34287
diff
changeset
|
72 |
ClassLoader::trace_class_path(msg, name); |
26135 | 73 |
MetaspaceShared::set_archive_loading_failed(); |
74 |
return false; |
|
75 |
} |
|
76 |
||
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46365
diff
changeset
|
77 |
void SharedPathsMiscInfo::print_path(outputStream* out, int type, const char* path) { |
36364
5971776598e5
8150103: Convert TraceClassPaths to Unified Logging
mockner
parents:
34287
diff
changeset
|
78 |
switch (type) { |
5971776598e5
8150103: Convert TraceClassPaths to Unified Logging
mockner
parents:
34287
diff
changeset
|
79 |
case BOOT: |
36508 | 80 |
out->print("Expecting BOOT path=%s", path); |
36364
5971776598e5
8150103: Convert TraceClassPaths to Unified Logging
mockner
parents:
34287
diff
changeset
|
81 |
break; |
5971776598e5
8150103: Convert TraceClassPaths to Unified Logging
mockner
parents:
34287
diff
changeset
|
82 |
case NON_EXIST: |
5971776598e5
8150103: Convert TraceClassPaths to Unified Logging
mockner
parents:
34287
diff
changeset
|
83 |
out->print("Expecting that %s does not exist", path); |
5971776598e5
8150103: Convert TraceClassPaths to Unified Logging
mockner
parents:
34287
diff
changeset
|
84 |
break; |
5971776598e5
8150103: Convert TraceClassPaths to Unified Logging
mockner
parents:
34287
diff
changeset
|
85 |
default: |
5971776598e5
8150103: Convert TraceClassPaths to Unified Logging
mockner
parents:
34287
diff
changeset
|
86 |
ShouldNotReachHere(); |
5971776598e5
8150103: Convert TraceClassPaths to Unified Logging
mockner
parents:
34287
diff
changeset
|
87 |
} |
5971776598e5
8150103: Convert TraceClassPaths to Unified Logging
mockner
parents:
34287
diff
changeset
|
88 |
} |
5971776598e5
8150103: Convert TraceClassPaths to Unified Logging
mockner
parents:
34287
diff
changeset
|
89 |
|
26135 | 90 |
bool SharedPathsMiscInfo::check() { |
91 |
// The whole buffer must be 0 terminated so that we can use strlen and strcmp |
|
92 |
// without fear. |
|
93 |
_end_ptr -= sizeof(jint); |
|
94 |
if (_cur_ptr >= _end_ptr) { |
|
95 |
return fail("Truncated archive file header"); |
|
96 |
} |
|
97 |
if (*_end_ptr != 0) { |
|
98 |
return fail("Corrupted archive file header"); |
|
99 |
} |
|
100 |
||
101 |
while (_cur_ptr < _end_ptr) { |
|
102 |
jint type; |
|
103 |
const char* path = _cur_ptr; |
|
104 |
_cur_ptr += strlen(path) + 1; |
|
105 |
if (!read_jint(&type)) { |
|
106 |
return fail("Corrupted archive file header"); |
|
107 |
} |
|
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46365
diff
changeset
|
108 |
LogTarget(Info, class, path) lt; |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46365
diff
changeset
|
109 |
if (lt.is_enabled()) { |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46365
diff
changeset
|
110 |
lt.print("type=%s ", type_name(type)); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46365
diff
changeset
|
111 |
LogStream ls(lt); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46365
diff
changeset
|
112 |
print_path(&ls, type, path); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46365
diff
changeset
|
113 |
ls.cr(); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46365
diff
changeset
|
114 |
} |
26135 | 115 |
if (!check(type, path)) { |
116 |
if (!PrintSharedArchiveAndExit) { |
|
117 |
return false; |
|
118 |
} |
|
119 |
} else { |
|
36364
5971776598e5
8150103: Convert TraceClassPaths to Unified Logging
mockner
parents:
34287
diff
changeset
|
120 |
ClassLoader::trace_class_path("ok"); |
26135 | 121 |
} |
122 |
} |
|
123 |
||
124 |
return true; |
|
125 |
} |
|
126 |
||
127 |
bool SharedPathsMiscInfo::check(jint type, const char* path) { |
|
128 |
switch (type) { |
|
129 |
case BOOT: |
|
27562 | 130 |
if (os::file_name_strcmp(path, Arguments::get_sysclasspath()) != 0) { |
36508 | 131 |
return fail("[BOOT classpath mismatch, actual =", Arguments::get_sysclasspath()); |
26135 | 132 |
} |
133 |
break; |
|
46365
d79745f72ae6
8171042: The 'REQUIRED' type in sharedPathsMiscInfo.hpp is not used and should be removed.
jiangli
parents:
42876
diff
changeset
|
134 |
case NON_EXIST: |
26135 | 135 |
{ |
136 |
struct stat st; |
|
46365
d79745f72ae6
8171042: The 'REQUIRED' type in sharedPathsMiscInfo.hpp is not used and should be removed.
jiangli
parents:
42876
diff
changeset
|
137 |
if (os::stat(path, &st) == 0) { |
26135 | 138 |
// The file actually exists |
46365
d79745f72ae6
8171042: The 'REQUIRED' type in sharedPathsMiscInfo.hpp is not used and should be removed.
jiangli
parents:
42876
diff
changeset
|
139 |
// But we want it to not exist -> fail |
d79745f72ae6
8171042: The 'REQUIRED' type in sharedPathsMiscInfo.hpp is not used and should be removed.
jiangli
parents:
42876
diff
changeset
|
140 |
return fail("File must not exist"); |
26135 | 141 |
} |
142 |
} |
|
143 |
break; |
|
144 |
default: |
|
145 |
return fail("Corrupted archive file header"); |
|
146 |
} |
|
147 |
||
148 |
return true; |
|
149 |
} |