src/hotspot/share/classfile/classFileStream.hpp
author lfoltan
Mon, 21 Oct 2019 13:13:16 -0400
changeset 58722 cba8afa5cfed
parent 54257 21702e87efdf
permissions -rw-r--r--
8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently Summary: Increase the use of type signature constants instead of hard coded characters within the JVM. Reviewed-by: coleenp, dholmes, fparain Contributed-by: lois.foltan@oracle.com, john.r.rose@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
    25
#ifndef SHARE_CLASSFILE_CLASSFILESTREAM_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
    26
#define SHARE_CLASSFILE_CLASSFILESTREAM_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
37466
287c4ebd11b0 8153967: Remove top.hpp
stefank
parents: 34666
diff changeset
    28
#include "memory/allocation.hpp"
25715
d5a8dbdc5150 8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents: 22234
diff changeset
    29
#include "utilities/bytes.hpp"
37466
287c4ebd11b0 8153967: Remove top.hpp
stefank
parents: 34666
diff changeset
    30
#include "utilities/exceptions.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// Input stream for reading .class file
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// The entire input stream is present in a buffer allocated by the caller.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// The caller is responsible for deallocating the buffer and for using
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// ResourceMarks appropriately when constructing streams.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    38
class ClassPathEntry;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    39
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
class ClassFileStream: public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
 private:
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    42
  const u1* const _buffer_start; // Buffer bottom
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    43
  const u1* const _buffer_end;   // Buffer top (one past last element)
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    44
  mutable const u1* _current;    // Current buffer position
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    45
  const char* const _source;     // Source of stream (directory name, ZIP/JAR archive name)
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    46
  bool _need_verify;             // True if verification is on for the class file
54257
21702e87efdf 8220095: Assertion failure when symlink (with different name) is used for lib/modules file
iklam
parents: 54042
diff changeset
    47
  bool _from_boot_loader_modules_image;  // True if this was created by ClassPathImageEntry.
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    48
  void truncated_file_error(TRAPS) const ;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    50
 protected:
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    51
  const u1* clone_buffer() const;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    52
  const char* const clone_source() const;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    53
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
 public:
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    55
  static const bool verify;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    56
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    57
  ClassFileStream(const u1* buffer,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    58
                  int length,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    59
                  const char* source,
54257
21702e87efdf 8220095: Assertion failure when symlink (with different name) is used for lib/modules file
iklam
parents: 54042
diff changeset
    60
                  bool verify_stream = verify,  // to be verified by default
21702e87efdf 8220095: Assertion failure when symlink (with different name) is used for lib/modules file
iklam
parents: 54042
diff changeset
    61
                  bool from_boot_loader_modules_image = false);
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    62
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    63
  virtual const ClassFileStream* clone() const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // Buffer access
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    66
  const u1* buffer() const { return _buffer_start; }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    67
  int length() const { return _buffer_end - _buffer_start; }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    68
  const u1* current() const { return _current; }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    69
  void set_current(const u1* pos) const {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    70
    assert(pos >= _buffer_start && pos <= _buffer_end, "invariant");
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    71
    _current = pos;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    72
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    74
  // for relative positioning
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    75
  juint current_offset() const {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    76
    return (juint)(_current - _buffer_start);
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    77
  }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    78
  const char* source() const { return _source; }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    79
  bool need_verify() const { return _need_verify; }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    80
  void set_verify(bool flag) { _need_verify = flag; }
54257
21702e87efdf 8220095: Assertion failure when symlink (with different name) is used for lib/modules file
iklam
parents: 54042
diff changeset
    81
  bool from_boot_loader_modules_image() const { return _from_boot_loader_modules_image; }
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    82
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    83
  void check_truncated_file(bool b, TRAPS) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    if (b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
      truncated_file_error(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    89
  void guarantee_more(int size, TRAPS) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    size_t remaining = (size_t)(_buffer_end - _current);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    unsigned int usize = (unsigned int)size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    check_truncated_file(usize > remaining, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // Read u1 from stream
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    96
  u1 get_u1_fast() const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    return *_current++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
54042
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
    99
  u1 get_u1(TRAPS) const {
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   100
    if (_need_verify) {
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   101
      guarantee_more(1, CHECK_0);
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   102
    } else {
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   103
      assert(1 <= _buffer_end - _current, "buffer overflow");
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   104
    }
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   105
    return get_u1_fast();
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   106
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // Read u2 from stream
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   109
  u2 get_u2_fast() const {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   110
    u2 res = Bytes::get_Java_u2((address)_current);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    _current += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
54042
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   114
  u2 get_u2(TRAPS) const {
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   115
    if (_need_verify) {
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   116
      guarantee_more(2, CHECK_0);
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   117
    } else {
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   118
      assert(2 <= _buffer_end - _current, "buffer overflow");
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   119
    }
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   120
    return get_u2_fast();
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   121
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  // Read u4 from stream
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   124
  u4 get_u4_fast() const {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   125
    u4 res = Bytes::get_Java_u4((address)_current);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    _current += 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // Read u8 from stream
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   131
  u8 get_u8_fast() const {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   132
    u8 res = Bytes::get_Java_u8((address)_current);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    _current += 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
54042
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   137
  // Skip length elements from stream
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   138
  void skip_u1(int length, TRAPS) const {
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   139
    if (_need_verify) {
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   140
      guarantee_more(length, CHECK);
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   141
    }
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   142
    skip_u1_fast(length);
6dd6f988b4e4 8219860: Cleanup ClassFileParser::parse_linenumber_table
redestad
parents: 53244
diff changeset
   143
  }
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   144
  void skip_u1_fast(int length) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    _current += length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   148
  void skip_u2_fast(int length) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    _current += 2 * length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   152
  void skip_u4_fast(int length) const {
15102
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 8921
diff changeset
   153
    _current += 4 * length;
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 8921
diff changeset
   154
  }
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 8921
diff changeset
   155
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  // Tells whether eos is reached
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   157
  bool at_eos() const { return _current == _buffer_end; }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   158
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37466
diff changeset
   159
  uint64_t compute_fingerprint() const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   161
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
   162
#endif // SHARE_CLASSFILE_CLASSFILESTREAM_HPP