author | kvn |
Fri, 24 Jun 2016 15:09:00 -0700 | |
changeset 39450 | 78e99b030d5f |
parent 37248 | 11a660dbbb8e |
child 42650 | 1f304d0c888b |
permissions | -rw-r--r-- |
1 | 1 |
/* |
37248 | 2 |
* Copyright (c) 1997, 2016, 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" |
|
37248 | 28 |
#include "memory/resourceArea.hpp" |
1 | 29 |
|
34666 | 30 |
const bool ClassFileStream::verify = true; |
31 |
const bool ClassFileStream::no_verification = false; |
|
32 |
||
33 |
void ClassFileStream::truncated_file_error(TRAPS) const { |
|
1 | 34 |
THROW_MSG(vmSymbols::java_lang_ClassFormatError(), "Truncated class file"); |
35 |
} |
|
36 |
||
34666 | 37 |
ClassFileStream::ClassFileStream(const u1* buffer, |
38 |
int length, |
|
39 |
const char* source, |
|
40 |
bool verify_stream) : |
|
41 |
_buffer_start(buffer), |
|
42 |
_buffer_end(buffer + length), |
|
43 |
_current(buffer), |
|
44 |
_source(source), |
|
45 |
_need_verify(verify_stream) {} |
|
46 |
||
47 |
const u1* ClassFileStream::clone_buffer() const { |
|
48 |
u1* const new_buffer_start = NEW_RESOURCE_ARRAY(u1, length()); |
|
49 |
memcpy(new_buffer_start, _buffer_start, length()); |
|
50 |
return new_buffer_start; |
|
1 | 51 |
} |
52 |
||
34666 | 53 |
const char* const ClassFileStream::clone_source() const { |
54 |
const char* const src = source(); |
|
55 |
char* source_copy = NULL; |
|
56 |
if (src != NULL) { |
|
57 |
size_t source_len = strlen(src); |
|
58 |
source_copy = NEW_RESOURCE_ARRAY(char, source_len + 1); |
|
59 |
strncpy(source_copy, src, source_len + 1); |
|
60 |
} |
|
61 |
return source_copy; |
|
62 |
} |
|
63 |
||
64 |
// Caller responsible for ResourceMark |
|
65 |
// clone stream with a rewound position |
|
66 |
const ClassFileStream* ClassFileStream::clone() const { |
|
67 |
const u1* const new_buffer_start = clone_buffer(); |
|
68 |
return new ClassFileStream(new_buffer_start, |
|
69 |
length(), |
|
70 |
clone_source(), |
|
71 |
need_verify()); |
|
72 |
} |
|
73 |
||
74 |
u1 ClassFileStream::get_u1(TRAPS) const { |
|
1 | 75 |
if (_need_verify) { |
76 |
guarantee_more(1, CHECK_0); |
|
77 |
} else { |
|
78 |
assert(1 <= _buffer_end - _current, "buffer overflow"); |
|
79 |
} |
|
80 |
return *_current++; |
|
81 |
} |
|
82 |
||
34666 | 83 |
u2 ClassFileStream::get_u2(TRAPS) const { |
1 | 84 |
if (_need_verify) { |
85 |
guarantee_more(2, CHECK_0); |
|
86 |
} else { |
|
87 |
assert(2 <= _buffer_end - _current, "buffer overflow"); |
|
88 |
} |
|
34666 | 89 |
const u1* tmp = _current; |
1 | 90 |
_current += 2; |
34666 | 91 |
return Bytes::get_Java_u2((address)tmp); |
1 | 92 |
} |
93 |
||
34666 | 94 |
u4 ClassFileStream::get_u4(TRAPS) const { |
1 | 95 |
if (_need_verify) { |
96 |
guarantee_more(4, CHECK_0); |
|
97 |
} else { |
|
98 |
assert(4 <= _buffer_end - _current, "buffer overflow"); |
|
99 |
} |
|
34666 | 100 |
const u1* tmp = _current; |
1 | 101 |
_current += 4; |
34666 | 102 |
return Bytes::get_Java_u4((address)tmp); |
1 | 103 |
} |
104 |
||
34666 | 105 |
u8 ClassFileStream::get_u8(TRAPS) const { |
1 | 106 |
if (_need_verify) { |
107 |
guarantee_more(8, CHECK_0); |
|
108 |
} else { |
|
109 |
assert(8 <= _buffer_end - _current, "buffer overflow"); |
|
110 |
} |
|
34666 | 111 |
const u1* tmp = _current; |
1 | 112 |
_current += 8; |
34666 | 113 |
return Bytes::get_Java_u8((address)tmp); |
1 | 114 |
} |
115 |
||
34666 | 116 |
void ClassFileStream::skip_u1(int length, TRAPS) const { |
1 | 117 |
if (_need_verify) { |
118 |
guarantee_more(length, CHECK); |
|
119 |
} |
|
120 |
_current += length; |
|
121 |
} |
|
122 |
||
34666 | 123 |
void ClassFileStream::skip_u2(int length, TRAPS) const { |
1 | 124 |
if (_need_verify) { |
125 |
guarantee_more(length * 2, CHECK); |
|
126 |
} |
|
127 |
_current += length * 2; |
|
128 |
} |
|
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7397
diff
changeset
|
129 |
|
34666 | 130 |
void ClassFileStream::skip_u4(int length, TRAPS) const { |
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7397
diff
changeset
|
131 |
if (_need_verify) { |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7397
diff
changeset
|
132 |
guarantee_more(length * 4, CHECK); |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7397
diff
changeset
|
133 |
} |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7397
diff
changeset
|
134 |
_current += length * 4; |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7397
diff
changeset
|
135 |
} |