Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/classfile/classFileStream.cpp
40949 views
1
/*
2
* Copyright (c) 1997, 2021, 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
#include "precompiled.hpp"
26
#include "classfile/classFileStream.hpp"
27
#include "classfile/classLoader.hpp"
28
#include "classfile/vmSymbols.hpp"
29
#include "memory/resourceArea.hpp"
30
31
const bool ClassFileStream::verify = true;
32
33
void ClassFileStream::truncated_file_error(TRAPS) const {
34
THROW_MSG(vmSymbols::java_lang_ClassFormatError(), "Truncated class file");
35
}
36
37
ClassFileStream::ClassFileStream(const u1* buffer,
38
int length,
39
const char* source,
40
bool verify_stream,
41
bool from_boot_loader_modules_image) :
42
_buffer_start(buffer),
43
_buffer_end(buffer + length),
44
_current(buffer),
45
_source(source),
46
_need_verify(verify_stream),
47
_from_boot_loader_modules_image(from_boot_loader_modules_image) {
48
assert(buffer != NULL, "caller should throw NPE");
49
}
50
51
const u1* ClassFileStream::clone_buffer() const {
52
u1* const new_buffer_start = NEW_RESOURCE_ARRAY(u1, length());
53
memcpy(new_buffer_start, _buffer_start, length());
54
return new_buffer_start;
55
}
56
57
const char* const ClassFileStream::clone_source() const {
58
const char* const src = source();
59
char* source_copy = NULL;
60
if (src != NULL) {
61
size_t source_len = strlen(src);
62
source_copy = NEW_RESOURCE_ARRAY(char, source_len + 1);
63
strncpy(source_copy, src, source_len + 1);
64
}
65
return source_copy;
66
}
67
68
// Caller responsible for ResourceMark
69
// clone stream with a rewound position
70
const ClassFileStream* ClassFileStream::clone() const {
71
const u1* const new_buffer_start = clone_buffer();
72
return new ClassFileStream(new_buffer_start,
73
length(),
74
clone_source(),
75
need_verify(),
76
from_boot_loader_modules_image());
77
}
78
79