author | alanb |
Tue, 03 May 2016 09:09:20 +0100 | |
changeset 37773 | e5b3e9732c3c |
parent 36508 | 5f9eee6b383b |
child 40016 | bf6fcd467a7b |
permissions | -rw-r--r-- |
34666 | 1 |
/* |
36386
d7f5e6df26df
8147442: Event-based tracing to allow for tracing Klass creation
mgronlun
parents:
34666
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
34666 | 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/classFileParser.hpp" |
|
27 |
#include "classfile/classFileStream.hpp" |
|
28 |
#include "classfile/classLoaderData.hpp" |
|
29 |
#include "classfile/klassFactory.hpp" |
|
30 |
#include "memory/resourceArea.hpp" |
|
31 |
#include "prims/jvmtiEnvBase.hpp" |
|
36386
d7f5e6df26df
8147442: Event-based tracing to allow for tracing Klass creation
mgronlun
parents:
34666
diff
changeset
|
32 |
#include "trace/traceMacros.hpp" |
34666 | 33 |
|
34 |
static ClassFileStream* prologue(ClassFileStream* stream, |
|
35 |
Symbol* name, |
|
36 |
ClassLoaderData* loader_data, |
|
37 |
Handle protection_domain, |
|
38 |
JvmtiCachedClassFileData** cached_class_file, |
|
39 |
TRAPS) { |
|
40 |
||
41 |
assert(stream != NULL, "invariant"); |
|
42 |
||
43 |
if (JvmtiExport::should_post_class_file_load_hook()) { |
|
44 |
assert(THREAD->is_Java_thread(), "must be a JavaThread"); |
|
45 |
const JavaThread* jt = (JavaThread*)THREAD; |
|
46 |
||
47 |
Handle class_loader(THREAD, loader_data->class_loader()); |
|
48 |
||
49 |
// Get the cached class file bytes (if any) from the class that |
|
50 |
// is being redefined or retransformed. We use jvmti_thread_state() |
|
51 |
// instead of JvmtiThreadState::state_for(jt) so we don't allocate |
|
52 |
// a JvmtiThreadState any earlier than necessary. This will help |
|
53 |
// avoid the bug described by 7126851. |
|
54 |
||
55 |
JvmtiThreadState* state = jt->jvmti_thread_state(); |
|
56 |
||
57 |
if (state != NULL) { |
|
58 |
KlassHandle* h_class_being_redefined = |
|
59 |
state->get_class_being_redefined(); |
|
60 |
||
61 |
if (h_class_being_redefined != NULL) { |
|
62 |
instanceKlassHandle ikh_class_being_redefined = |
|
63 |
instanceKlassHandle(THREAD, (*h_class_being_redefined)()); |
|
64 |
||
65 |
*cached_class_file = ikh_class_being_redefined->get_cached_class_file(); |
|
66 |
} |
|
67 |
} |
|
68 |
||
69 |
unsigned char* ptr = const_cast<unsigned char*>(stream->buffer()); |
|
70 |
unsigned char* end_ptr = ptr + stream->length(); |
|
71 |
||
72 |
JvmtiExport::post_class_file_load_hook(name, |
|
73 |
class_loader, |
|
74 |
protection_domain, |
|
75 |
&ptr, |
|
76 |
&end_ptr, |
|
77 |
cached_class_file); |
|
78 |
||
79 |
if (ptr != stream->buffer()) { |
|
80 |
// JVMTI agent has modified class file data. |
|
81 |
// Set new class file stream using JVMTI agent modified class file data. |
|
82 |
stream = new ClassFileStream(ptr, |
|
83 |
end_ptr - ptr, |
|
84 |
stream->source(), |
|
85 |
stream->need_verify()); |
|
86 |
} |
|
87 |
} |
|
88 |
||
89 |
return stream; |
|
90 |
} |
|
91 |
||
92 |
||
93 |
instanceKlassHandle KlassFactory::create_from_stream(ClassFileStream* stream, |
|
94 |
Symbol* name, |
|
95 |
ClassLoaderData* loader_data, |
|
96 |
Handle protection_domain, |
|
97 |
const Klass* host_klass, |
|
98 |
GrowableArray<Handle>* cp_patches, |
|
99 |
TempNewSymbol* parsed_name, |
|
100 |
TRAPS) { |
|
101 |
||
102 |
assert(stream != NULL, "invariant"); |
|
103 |
assert(loader_data != NULL, "invariant"); |
|
104 |
assert(THREAD->is_Java_thread(), "must be a JavaThread"); |
|
105 |
||
36508 | 106 |
bool changed_by_loadhook = false; |
107 |
||
34666 | 108 |
ResourceMark rm; |
109 |
HandleMark hm; |
|
110 |
||
111 |
JvmtiCachedClassFileData* cached_class_file = NULL; |
|
112 |
||
36508 | 113 |
ClassFileStream* old_stream = stream; |
114 |
||
34666 | 115 |
stream = prologue(stream, |
116 |
name, |
|
117 |
loader_data, |
|
118 |
protection_domain, |
|
119 |
&cached_class_file, |
|
120 |
CHECK_NULL); |
|
121 |
||
122 |
ClassFileParser parser(stream, |
|
123 |
name, |
|
124 |
loader_data, |
|
125 |
protection_domain, |
|
126 |
parsed_name, |
|
127 |
host_klass, |
|
128 |
cp_patches, |
|
129 |
ClassFileParser::BROADCAST, // publicity level |
|
130 |
CHECK_NULL); |
|
131 |
||
36508 | 132 |
instanceKlassHandle result = parser.create_instance_klass(old_stream != stream, CHECK_NULL); |
133 |
assert(result == parser.create_instance_klass(old_stream != stream, THREAD), "invariant"); |
|
34666 | 134 |
|
135 |
if (result.is_null()) { |
|
136 |
return NULL; |
|
137 |
} |
|
138 |
||
139 |
if (cached_class_file != NULL) { |
|
140 |
// JVMTI: we have an InstanceKlass now, tell it about the cached bytes |
|
141 |
result->set_cached_class_file(cached_class_file); |
|
142 |
} |
|
143 |
||
36386
d7f5e6df26df
8147442: Event-based tracing to allow for tracing Klass creation
mgronlun
parents:
34666
diff
changeset
|
144 |
TRACE_KLASS_CREATION(result, parser, THREAD); |
d7f5e6df26df
8147442: Event-based tracing to allow for tracing Klass creation
mgronlun
parents:
34666
diff
changeset
|
145 |
|
34666 | 146 |
return result; |
147 |
} |