Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/classfile/classFileStream.cpp
32285 views
/*1* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "classfile/classFileStream.hpp"26#include "classfile/vmSymbols.hpp"2728void ClassFileStream::truncated_file_error(TRAPS) {29THROW_MSG(vmSymbols::java_lang_ClassFormatError(), "Truncated class file");30}3132ClassFileStream::ClassFileStream(u1* buffer, int length, const char* source, bool need_verify) {33_buffer_start = buffer;34_buffer_end = buffer + length;35_current = buffer;36_source = source;37_need_verify = need_verify;38}3940u1 ClassFileStream::get_u1(TRAPS) {41if (_need_verify) {42guarantee_more(1, CHECK_0);43} else {44assert(1 <= _buffer_end - _current, "buffer overflow");45}46return *_current++;47}4849u2 ClassFileStream::get_u2(TRAPS) {50if (_need_verify) {51guarantee_more(2, CHECK_0);52} else {53assert(2 <= _buffer_end - _current, "buffer overflow");54}55u1* tmp = _current;56_current += 2;57return Bytes::get_Java_u2(tmp);58}5960u4 ClassFileStream::get_u4(TRAPS) {61if (_need_verify) {62guarantee_more(4, CHECK_0);63} else {64assert(4 <= _buffer_end - _current, "buffer overflow");65}66u1* tmp = _current;67_current += 4;68return Bytes::get_Java_u4(tmp);69}7071u8 ClassFileStream::get_u8(TRAPS) {72if (_need_verify) {73guarantee_more(8, CHECK_0);74} else {75assert(8 <= _buffer_end - _current, "buffer overflow");76}77u1* tmp = _current;78_current += 8;79return Bytes::get_Java_u8(tmp);80}8182void ClassFileStream::skip_u1(int length, TRAPS) {83if (_need_verify) {84guarantee_more(length, CHECK);85}86_current += length;87}8889void ClassFileStream::skip_u2(int length, TRAPS) {90if (_need_verify) {91guarantee_more(length * 2, CHECK);92}93_current += length * 2;94}9596void ClassFileStream::skip_u4(int length, TRAPS) {97if (_need_verify) {98guarantee_more(length * 4, CHECK);99}100_current += length * 4;101}102103#if INCLUDE_JFR104105u1* ClassFileStream::clone_buffer() const {106u1* const new_buffer_start = NEW_RESOURCE_ARRAY(u1, length());107memcpy(new_buffer_start, _buffer_start, length());108return new_buffer_start;109}110111const char* const ClassFileStream::clone_source() const {112const char* const src = source();113char* source_copy = NULL;114if (src != NULL) {115size_t source_len = strlen(src);116source_copy = NEW_RESOURCE_ARRAY(char, source_len + 1);117strncpy(source_copy, src, source_len + 1);118}119return source_copy;120}121122ClassFileStream* ClassFileStream::clone() const {123u1* const new_buffer_start = clone_buffer();124return new ClassFileStream(new_buffer_start,125length(),126clone_source(),127need_verify());128}129#endif // INCLUDE_JFR130131132