1 /*
2 * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
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 // Input stream for reading .class file
26 //
27 // The entire input stream is present in a buffer allocated by the caller.
28 // The caller is responsible for deallocating the buffer and for using
29 // ResourceMarks appropriately when constructing streams.
30
31 class ClassFileStream: public ResourceObj {
32 private:
33 u1* _buffer_start; // Buffer bottom
34 u1* _buffer_end; // Buffer top (one past last element)
35 u1* _current; // Current buffer position
36 char* _source; // Source of stream (directory name, ZIP/JAR archive name)
37 bool _need_verify; // True if verification is on for the class file
38
39 void truncated_file_error(TRAPS);
40 public:
41 // Constructor
42 ClassFileStream(u1* buffer, int length, char* source);
43
44 // Buffer access
99 }
100
101 u2* get_u2_buffer() {
102 return (u2*) _current;
103 }
104
105 // Skip length u1 or u2 elements from stream
106 void skip_u1(int length, TRAPS);
107 void skip_u1_fast(int length) {
108 _current += length;
109 }
110
111 void skip_u2(int length, TRAPS);
112 void skip_u2_fast(int length) {
113 _current += 2 * length;
114 }
115
116 // Tells whether eos is reached
117 bool at_eos() const { return _current == _buffer_end; }
118 };
|
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
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 #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
38
39 // Input stream for reading .class file
40 //
41 // The entire input stream is present in a buffer allocated by the caller.
42 // The caller is responsible for deallocating the buffer and for using
43 // ResourceMarks appropriately when constructing streams.
44
45 class ClassFileStream: public ResourceObj {
46 private:
47 u1* _buffer_start; // Buffer bottom
48 u1* _buffer_end; // Buffer top (one past last element)
49 u1* _current; // Current buffer position
50 char* _source; // Source of stream (directory name, ZIP/JAR archive name)
51 bool _need_verify; // True if verification is on for the class file
52
53 void truncated_file_error(TRAPS);
54 public:
55 // Constructor
56 ClassFileStream(u1* buffer, int length, char* source);
57
58 // Buffer access
113 }
114
115 u2* get_u2_buffer() {
116 return (u2*) _current;
117 }
118
119 // Skip length u1 or u2 elements from stream
120 void skip_u1(int length, TRAPS);
121 void skip_u1_fast(int length) {
122 _current += length;
123 }
124
125 void skip_u2(int length, TRAPS);
126 void skip_u2_fast(int length) {
127 _current += 2 * length;
128 }
129
130 // Tells whether eos is reached
131 bool at_eos() const { return _current == _buffer_end; }
132 };
133
134 #endif // SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP
|