Tue, 20 Jul 2010 08:41:42 -0700
6964170: Verifier crashes
Summary: Check if klassOop != NULL rather than klass_part != NULL
Reviewed-by: kamg, never
duke@435 | 1 | /* |
trims@1907 | 2 | * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | // Input stream for reading .class file |
duke@435 | 26 | // |
duke@435 | 27 | // The entire input stream is present in a buffer allocated by the caller. |
duke@435 | 28 | // The caller is responsible for deallocating the buffer and for using |
duke@435 | 29 | // ResourceMarks appropriately when constructing streams. |
duke@435 | 30 | |
duke@435 | 31 | class ClassFileStream: public ResourceObj { |
duke@435 | 32 | private: |
duke@435 | 33 | u1* _buffer_start; // Buffer bottom |
duke@435 | 34 | u1* _buffer_end; // Buffer top (one past last element) |
duke@435 | 35 | u1* _current; // Current buffer position |
duke@435 | 36 | char* _source; // Source of stream (directory name, ZIP/JAR archive name) |
duke@435 | 37 | bool _need_verify; // True if verification is on for the class file |
duke@435 | 38 | |
duke@435 | 39 | void truncated_file_error(TRAPS); |
duke@435 | 40 | public: |
duke@435 | 41 | // Constructor |
duke@435 | 42 | ClassFileStream(u1* buffer, int length, char* source); |
duke@435 | 43 | |
duke@435 | 44 | // Buffer access |
duke@435 | 45 | u1* buffer() const { return _buffer_start; } |
duke@435 | 46 | int length() const { return _buffer_end - _buffer_start; } |
duke@435 | 47 | u1* current() const { return _current; } |
duke@435 | 48 | void set_current(u1* pos) { _current = pos; } |
duke@435 | 49 | char* source() const { return _source; } |
duke@435 | 50 | void set_verify(bool flag) { _need_verify = flag; } |
duke@435 | 51 | |
duke@435 | 52 | void check_truncated_file(bool b, TRAPS) { |
duke@435 | 53 | if (b) { |
duke@435 | 54 | truncated_file_error(THREAD); |
duke@435 | 55 | } |
duke@435 | 56 | } |
duke@435 | 57 | |
duke@435 | 58 | void guarantee_more(int size, TRAPS) { |
duke@435 | 59 | size_t remaining = (size_t)(_buffer_end - _current); |
duke@435 | 60 | unsigned int usize = (unsigned int)size; |
duke@435 | 61 | check_truncated_file(usize > remaining, CHECK); |
duke@435 | 62 | } |
duke@435 | 63 | |
duke@435 | 64 | // Read u1 from stream |
duke@435 | 65 | u1 get_u1(TRAPS); |
duke@435 | 66 | u1 get_u1_fast() { |
duke@435 | 67 | return *_current++; |
duke@435 | 68 | } |
duke@435 | 69 | |
duke@435 | 70 | // Read u2 from stream |
duke@435 | 71 | u2 get_u2(TRAPS); |
duke@435 | 72 | u2 get_u2_fast() { |
duke@435 | 73 | u2 res = Bytes::get_Java_u2(_current); |
duke@435 | 74 | _current += 2; |
duke@435 | 75 | return res; |
duke@435 | 76 | } |
duke@435 | 77 | |
duke@435 | 78 | // Read u4 from stream |
duke@435 | 79 | u4 get_u4(TRAPS); |
duke@435 | 80 | u4 get_u4_fast() { |
duke@435 | 81 | u4 res = Bytes::get_Java_u4(_current); |
duke@435 | 82 | _current += 4; |
duke@435 | 83 | return res; |
duke@435 | 84 | } |
duke@435 | 85 | |
duke@435 | 86 | // Read u8 from stream |
duke@435 | 87 | u8 get_u8(TRAPS); |
duke@435 | 88 | u8 get_u8_fast() { |
duke@435 | 89 | u8 res = Bytes::get_Java_u8(_current); |
duke@435 | 90 | _current += 8; |
duke@435 | 91 | return res; |
duke@435 | 92 | } |
duke@435 | 93 | |
duke@435 | 94 | // Get direct pointer into stream at current position. |
duke@435 | 95 | // Returns NULL if length elements are not remaining. The caller is |
duke@435 | 96 | // responsible for calling skip below if buffer contents is used. |
duke@435 | 97 | u1* get_u1_buffer() { |
duke@435 | 98 | return _current; |
duke@435 | 99 | } |
duke@435 | 100 | |
duke@435 | 101 | u2* get_u2_buffer() { |
duke@435 | 102 | return (u2*) _current; |
duke@435 | 103 | } |
duke@435 | 104 | |
duke@435 | 105 | // Skip length u1 or u2 elements from stream |
duke@435 | 106 | void skip_u1(int length, TRAPS); |
duke@435 | 107 | void skip_u1_fast(int length) { |
duke@435 | 108 | _current += length; |
duke@435 | 109 | } |
duke@435 | 110 | |
duke@435 | 111 | void skip_u2(int length, TRAPS); |
duke@435 | 112 | void skip_u2_fast(int length) { |
duke@435 | 113 | _current += 2 * length; |
duke@435 | 114 | } |
duke@435 | 115 | |
duke@435 | 116 | // Tells whether eos is reached |
duke@435 | 117 | bool at_eos() const { return _current == _buffer_end; } |
duke@435 | 118 | }; |