author | twisti |
Thu, 08 Sep 2011 05:11:31 -0700 | |
changeset 10540 | 92d59dba2407 |
parent 8921 | 14bfe81f2a9d |
child 15102 | 0a86564e5f61 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
8921
14bfe81f2a9d
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents:
8107
diff
changeset
|
2 |
* Copyright (c) 1997, 2011, 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 |
#ifndef SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP |
26 |
#define SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP |
|
27 |
||
28 |
#include "utilities/top.hpp" |
|
29 |
#ifdef TARGET_ARCH_x86 |
|
30 |
# include "bytes_x86.hpp" |
|
31 |
#endif |
|
32 |
#ifdef TARGET_ARCH_sparc |
|
33 |
# include "bytes_sparc.hpp" |
|
34 |
#endif |
|
35 |
#ifdef TARGET_ARCH_zero |
|
36 |
# include "bytes_zero.hpp" |
|
37 |
#endif |
|
8107
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
7397
diff
changeset
|
38 |
#ifdef TARGET_ARCH_arm |
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
7397
diff
changeset
|
39 |
# include "bytes_arm.hpp" |
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
7397
diff
changeset
|
40 |
#endif |
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
7397
diff
changeset
|
41 |
#ifdef TARGET_ARCH_ppc |
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
7397
diff
changeset
|
42 |
# include "bytes_ppc.hpp" |
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
7397
diff
changeset
|
43 |
#endif |
7397 | 44 |
|
1 | 45 |
// Input stream for reading .class file |
46 |
// |
|
47 |
// The entire input stream is present in a buffer allocated by the caller. |
|
48 |
// The caller is responsible for deallocating the buffer and for using |
|
49 |
// ResourceMarks appropriately when constructing streams. |
|
50 |
||
51 |
class ClassFileStream: public ResourceObj { |
|
52 |
private: |
|
53 |
u1* _buffer_start; // Buffer bottom |
|
54 |
u1* _buffer_end; // Buffer top (one past last element) |
|
55 |
u1* _current; // Current buffer position |
|
56 |
char* _source; // Source of stream (directory name, ZIP/JAR archive name) |
|
57 |
bool _need_verify; // True if verification is on for the class file |
|
58 |
||
59 |
void truncated_file_error(TRAPS); |
|
60 |
public: |
|
61 |
// Constructor |
|
62 |
ClassFileStream(u1* buffer, int length, char* source); |
|
63 |
||
64 |
// Buffer access |
|
65 |
u1* buffer() const { return _buffer_start; } |
|
66 |
int length() const { return _buffer_end - _buffer_start; } |
|
67 |
u1* current() const { return _current; } |
|
68 |
void set_current(u1* pos) { _current = pos; } |
|
69 |
char* source() const { return _source; } |
|
70 |
void set_verify(bool flag) { _need_verify = flag; } |
|
71 |
||
72 |
void check_truncated_file(bool b, TRAPS) { |
|
73 |
if (b) { |
|
74 |
truncated_file_error(THREAD); |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
void guarantee_more(int size, TRAPS) { |
|
79 |
size_t remaining = (size_t)(_buffer_end - _current); |
|
80 |
unsigned int usize = (unsigned int)size; |
|
81 |
check_truncated_file(usize > remaining, CHECK); |
|
82 |
} |
|
83 |
||
84 |
// Read u1 from stream |
|
85 |
u1 get_u1(TRAPS); |
|
86 |
u1 get_u1_fast() { |
|
87 |
return *_current++; |
|
88 |
} |
|
89 |
||
90 |
// Read u2 from stream |
|
91 |
u2 get_u2(TRAPS); |
|
92 |
u2 get_u2_fast() { |
|
93 |
u2 res = Bytes::get_Java_u2(_current); |
|
94 |
_current += 2; |
|
95 |
return res; |
|
96 |
} |
|
97 |
||
98 |
// Read u4 from stream |
|
99 |
u4 get_u4(TRAPS); |
|
100 |
u4 get_u4_fast() { |
|
101 |
u4 res = Bytes::get_Java_u4(_current); |
|
102 |
_current += 4; |
|
103 |
return res; |
|
104 |
} |
|
105 |
||
106 |
// Read u8 from stream |
|
107 |
u8 get_u8(TRAPS); |
|
108 |
u8 get_u8_fast() { |
|
109 |
u8 res = Bytes::get_Java_u8(_current); |
|
110 |
_current += 8; |
|
111 |
return res; |
|
112 |
} |
|
113 |
||
114 |
// Get direct pointer into stream at current position. |
|
115 |
// Returns NULL if length elements are not remaining. The caller is |
|
116 |
// responsible for calling skip below if buffer contents is used. |
|
117 |
u1* get_u1_buffer() { |
|
118 |
return _current; |
|
119 |
} |
|
120 |
||
121 |
u2* get_u2_buffer() { |
|
122 |
return (u2*) _current; |
|
123 |
} |
|
124 |
||
125 |
// Skip length u1 or u2 elements from stream |
|
126 |
void skip_u1(int length, TRAPS); |
|
127 |
void skip_u1_fast(int length) { |
|
128 |
_current += length; |
|
129 |
} |
|
130 |
||
131 |
void skip_u2(int length, TRAPS); |
|
132 |
void skip_u2_fast(int length) { |
|
133 |
_current += 2 * length; |
|
134 |
} |
|
135 |
||
136 |
// Tells whether eos is reached |
|
137 |
bool at_eos() const { return _current == _buffer_end; } |
|
138 |
}; |
|
7397 | 139 |
|
140 |
#endif // SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP |