src/share/vm/classfile/classFileStream.hpp

Mon, 12 Aug 2019 18:30:40 +0300

author
apetushkov
date
Mon, 12 Aug 2019 18:30:40 +0300
changeset 9858
b985cbb00e68
parent 7090
bb239308be67
child 9931
fd44df5e3bc3
permissions
-rw-r--r--

8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens

duke@435 1 /*
apetushkov@9858 2 * Copyright (c) 1997, 2015, 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
stefank@2314 25 #ifndef SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP
stefank@2314 26 #define SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP
stefank@2314 27
stefank@2314 28 #include "utilities/top.hpp"
stefank@2314 29 #ifdef TARGET_ARCH_x86
stefank@2314 30 # include "bytes_x86.hpp"
stefank@2314 31 #endif
stefank@2314 32 #ifdef TARGET_ARCH_sparc
stefank@2314 33 # include "bytes_sparc.hpp"
stefank@2314 34 #endif
stefank@2314 35 #ifdef TARGET_ARCH_zero
stefank@2314 36 # include "bytes_zero.hpp"
stefank@2314 37 #endif
bobv@2508 38 #ifdef TARGET_ARCH_arm
bobv@2508 39 # include "bytes_arm.hpp"
bobv@2508 40 #endif
bobv@2508 41 #ifdef TARGET_ARCH_ppc
bobv@2508 42 # include "bytes_ppc.hpp"
bobv@2508 43 #endif
stefank@2314 44
duke@435 45 // Input stream for reading .class file
duke@435 46 //
duke@435 47 // The entire input stream is present in a buffer allocated by the caller.
duke@435 48 // The caller is responsible for deallocating the buffer and for using
duke@435 49 // ResourceMarks appropriately when constructing streams.
duke@435 50
duke@435 51 class ClassFileStream: public ResourceObj {
duke@435 52 private:
duke@435 53 u1* _buffer_start; // Buffer bottom
duke@435 54 u1* _buffer_end; // Buffer top (one past last element)
duke@435 55 u1* _current; // Current buffer position
iklam@7090 56 const char* _source; // Source of stream (directory name, ZIP/JAR archive name)
duke@435 57 bool _need_verify; // True if verification is on for the class file
duke@435 58
duke@435 59 void truncated_file_error(TRAPS);
apetushkov@9858 60
apetushkov@9858 61 #if INCLUDE_JFR
apetushkov@9858 62 u1* clone_buffer() const;
apetushkov@9858 63 const char* const clone_source() const;
apetushkov@9858 64 #endif
apetushkov@9858 65
duke@435 66 public:
duke@435 67 // Constructor
apetushkov@9858 68 ClassFileStream(u1* buffer, int length, const char* source, bool need_verify = false);
duke@435 69
duke@435 70 // Buffer access
duke@435 71 u1* buffer() const { return _buffer_start; }
duke@435 72 int length() const { return _buffer_end - _buffer_start; }
duke@435 73 u1* current() const { return _current; }
duke@435 74 void set_current(u1* pos) { _current = pos; }
apetushkov@9858 75 // for relative positioning
apetushkov@9858 76 juint current_offset() const {
apetushkov@9858 77 return (juint)(_current - _buffer_start);
apetushkov@9858 78 }
iklam@7090 79 const char* source() const { return _source; }
duke@435 80 void set_verify(bool flag) { _need_verify = flag; }
duke@435 81
duke@435 82 void check_truncated_file(bool b, TRAPS) {
duke@435 83 if (b) {
duke@435 84 truncated_file_error(THREAD);
duke@435 85 }
duke@435 86 }
duke@435 87
duke@435 88 void guarantee_more(int size, TRAPS) {
duke@435 89 size_t remaining = (size_t)(_buffer_end - _current);
duke@435 90 unsigned int usize = (unsigned int)size;
duke@435 91 check_truncated_file(usize > remaining, CHECK);
duke@435 92 }
duke@435 93
duke@435 94 // Read u1 from stream
duke@435 95 u1 get_u1(TRAPS);
duke@435 96 u1 get_u1_fast() {
duke@435 97 return *_current++;
duke@435 98 }
duke@435 99
duke@435 100 // Read u2 from stream
duke@435 101 u2 get_u2(TRAPS);
duke@435 102 u2 get_u2_fast() {
duke@435 103 u2 res = Bytes::get_Java_u2(_current);
duke@435 104 _current += 2;
duke@435 105 return res;
duke@435 106 }
duke@435 107
duke@435 108 // Read u4 from stream
duke@435 109 u4 get_u4(TRAPS);
duke@435 110 u4 get_u4_fast() {
duke@435 111 u4 res = Bytes::get_Java_u4(_current);
duke@435 112 _current += 4;
duke@435 113 return res;
duke@435 114 }
duke@435 115
duke@435 116 // Read u8 from stream
duke@435 117 u8 get_u8(TRAPS);
duke@435 118 u8 get_u8_fast() {
duke@435 119 u8 res = Bytes::get_Java_u8(_current);
duke@435 120 _current += 8;
duke@435 121 return res;
duke@435 122 }
duke@435 123
duke@435 124 // Get direct pointer into stream at current position.
duke@435 125 // Returns NULL if length elements are not remaining. The caller is
duke@435 126 // responsible for calling skip below if buffer contents is used.
duke@435 127 u1* get_u1_buffer() {
duke@435 128 return _current;
duke@435 129 }
duke@435 130
duke@435 131 u2* get_u2_buffer() {
duke@435 132 return (u2*) _current;
duke@435 133 }
duke@435 134
duke@435 135 // Skip length u1 or u2 elements from stream
duke@435 136 void skip_u1(int length, TRAPS);
duke@435 137 void skip_u1_fast(int length) {
duke@435 138 _current += length;
duke@435 139 }
duke@435 140
duke@435 141 void skip_u2(int length, TRAPS);
duke@435 142 void skip_u2_fast(int length) {
duke@435 143 _current += 2 * length;
duke@435 144 }
duke@435 145
coleenp@4398 146 void skip_u4(int length, TRAPS);
coleenp@4398 147 void skip_u4_fast(int length) {
coleenp@4398 148 _current += 4 * length;
coleenp@4398 149 }
coleenp@4398 150
duke@435 151 // Tells whether eos is reached
duke@435 152 bool at_eos() const { return _current == _buffer_end; }
apetushkov@9858 153
apetushkov@9858 154 #if INCLUDE_JFR
apetushkov@9858 155 ClassFileStream* clone() const;
apetushkov@9858 156
apetushkov@9858 157 bool need_verify() const { return _need_verify; }
apetushkov@9858 158 #endif
duke@435 159 };
stefank@2314 160
stefank@2314 161 #endif // SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP

mercurial