Path: blob/master/src/hotspot/share/classfile/classFileStream.cpp
40949 views
/*1* Copyright (c) 1997, 2021, 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/classLoader.hpp"27#include "classfile/vmSymbols.hpp"28#include "memory/resourceArea.hpp"2930const bool ClassFileStream::verify = true;3132void ClassFileStream::truncated_file_error(TRAPS) const {33THROW_MSG(vmSymbols::java_lang_ClassFormatError(), "Truncated class file");34}3536ClassFileStream::ClassFileStream(const u1* buffer,37int length,38const char* source,39bool verify_stream,40bool from_boot_loader_modules_image) :41_buffer_start(buffer),42_buffer_end(buffer + length),43_current(buffer),44_source(source),45_need_verify(verify_stream),46_from_boot_loader_modules_image(from_boot_loader_modules_image) {47assert(buffer != NULL, "caller should throw NPE");48}4950const u1* ClassFileStream::clone_buffer() const {51u1* const new_buffer_start = NEW_RESOURCE_ARRAY(u1, length());52memcpy(new_buffer_start, _buffer_start, length());53return new_buffer_start;54}5556const char* const ClassFileStream::clone_source() const {57const char* const src = source();58char* source_copy = NULL;59if (src != NULL) {60size_t source_len = strlen(src);61source_copy = NEW_RESOURCE_ARRAY(char, source_len + 1);62strncpy(source_copy, src, source_len + 1);63}64return source_copy;65}6667// Caller responsible for ResourceMark68// clone stream with a rewound position69const ClassFileStream* ClassFileStream::clone() const {70const u1* const new_buffer_start = clone_buffer();71return new ClassFileStream(new_buffer_start,72length(),73clone_source(),74need_verify(),75from_boot_loader_modules_image());76}777879