author | shade |
Thu, 03 Mar 2016 23:57:29 +0300 | |
changeset 36553 | 203b2b5d149b |
parent 34666 | 1c7168ea0034 |
child 37248 | 11a660dbbb8e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
34666 | 2 |
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "classfile/classFileStream.hpp" |
|
27 |
#include "classfile/vmSymbols.hpp" |
|
1 | 28 |
|
34666 | 29 |
const bool ClassFileStream::verify = true; |
30 |
const bool ClassFileStream::no_verification = false; |
|
31 |
||
32 |
void ClassFileStream::truncated_file_error(TRAPS) const { |
|
1 | 33 |
THROW_MSG(vmSymbols::java_lang_ClassFormatError(), "Truncated class file"); |
34 |
} |
|
35 |
||
34666 | 36 |
ClassFileStream::ClassFileStream(const u1* buffer, |
37 |
int length, |
|
38 |
const char* source, |
|
39 |
bool verify_stream) : |
|
40 |
_buffer_start(buffer), |
|
41 |
_buffer_end(buffer + length), |
|
42 |
_current(buffer), |
|
43 |
_source(source), |
|
44 |
_need_verify(verify_stream) {} |
|
45 |
||
46 |
const u1* ClassFileStream::clone_buffer() const { |
|
47 |
u1* const new_buffer_start = NEW_RESOURCE_ARRAY(u1, length()); |
|
48 |
memcpy(new_buffer_start, _buffer_start, length()); |
|
49 |
return new_buffer_start; |
|
1 | 50 |
} |
51 |
||
34666 | 52 |
const char* const ClassFileStream::clone_source() const { |
53 |
const char* const src = source(); |
|
54 |
char* source_copy = NULL; |
|
55 |
if (src != NULL) { |
|
56 |
size_t source_len = strlen(src); |
|
57 |
source_copy = NEW_RESOURCE_ARRAY(char, source_len + 1); |
|
58 |
strncpy(source_copy, src, source_len + 1); |
|
59 |
} |
|
60 |
return source_copy; |
|
61 |
} |
|
62 |
||
63 |
// Caller responsible for ResourceMark |
|
64 |
// clone stream with a rewound position |
|
65 |
const ClassFileStream* ClassFileStream::clone() const { |
|
66 |
const u1* const new_buffer_start = clone_buffer(); |
|
67 |
return new ClassFileStream(new_buffer_start, |
|
68 |
length(), |
|
69 |
clone_source(), |
|
70 |
need_verify()); |
|
71 |
} |
|
72 |
||
73 |
u1 ClassFileStream::get_u1(TRAPS) const { |
|
1 | 74 |
if (_need_verify) { |
75 |
guarantee_more(1, CHECK_0); |
|
76 |
} else { |
|
77 |
assert(1 <= _buffer_end - _current, "buffer overflow"); |
|
78 |
} |
|
79 |
return *_current++; |
|
80 |
} |
|
81 |
||
34666 | 82 |
u2 ClassFileStream::get_u2(TRAPS) const { |
1 | 83 |
if (_need_verify) { |
84 |
guarantee_more(2, CHECK_0); |
|
85 |
} else { |
|
86 |
assert(2 <= _buffer_end - _current, "buffer overflow"); |
|
87 |
} |
|
34666 | 88 |
const u1* tmp = _current; |
1 | 89 |
_current += 2; |
34666 | 90 |
return Bytes::get_Java_u2((address)tmp); |
1 | 91 |
} |
92 |
||
34666 | 93 |
u4 ClassFileStream::get_u4(TRAPS) const { |
1 | 94 |
if (_need_verify) { |
95 |
guarantee_more(4, CHECK_0); |
|
96 |
} else { |
|
97 |
assert(4 <= _buffer_end - _current, "buffer overflow"); |
|
98 |
} |
|
34666 | 99 |
const u1* tmp = _current; |
1 | 100 |
_current += 4; |
34666 | 101 |
return Bytes::get_Java_u4((address)tmp); |
1 | 102 |
} |
103 |
||
34666 | 104 |
u8 ClassFileStream::get_u8(TRAPS) const { |
1 | 105 |
if (_need_verify) { |
106 |
guarantee_more(8, CHECK_0); |
|
107 |
} else { |
|
108 |
assert(8 <= _buffer_end - _current, "buffer overflow"); |
|
109 |
} |
|
34666 | 110 |
const u1* tmp = _current; |
1 | 111 |
_current += 8; |
34666 | 112 |
return Bytes::get_Java_u8((address)tmp); |
1 | 113 |
} |
114 |
||
34666 | 115 |
void ClassFileStream::skip_u1(int length, TRAPS) const { |
1 | 116 |
if (_need_verify) { |
117 |
guarantee_more(length, CHECK); |
|
118 |
} |
|
119 |
_current += length; |
|
120 |
} |
|
121 |
||
34666 | 122 |
void ClassFileStream::skip_u2(int length, TRAPS) const { |
1 | 123 |
if (_need_verify) { |
124 |
guarantee_more(length * 2, CHECK); |
|
125 |
} |
|
126 |
_current += length * 2; |
|
127 |
} |
|
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7397
diff
changeset
|
128 |
|
34666 | 129 |
void ClassFileStream::skip_u4(int length, TRAPS) const { |
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7397
diff
changeset
|
130 |
if (_need_verify) { |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7397
diff
changeset
|
131 |
guarantee_more(length * 4, CHECK); |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7397
diff
changeset
|
132 |
} |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7397
diff
changeset
|
133 |
_current += length * 4; |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7397
diff
changeset
|
134 |
} |