hotspot/src/share/vm/classfile/classFileStream.hpp
author mikael
Tue, 24 Dec 2013 11:48:39 -0800
changeset 22234 da823d78ad65
parent 15102 0a86564e5f61
child 25715 d5a8dbdc5150
permissions -rw-r--r--
8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013 Summary: Copyright year updated for files modified during 2013 Reviewed-by: twisti, iveresov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
22234
da823d78ad65 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 15102
diff changeset
     2
 * Copyright (c) 1997, 2013, 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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "utilities/top.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#ifdef TARGET_ARCH_x86
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
# include "bytes_x86.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#ifdef TARGET_ARCH_sparc
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
# include "bytes_sparc.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#ifdef TARGET_ARCH_zero
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
# include "bytes_zero.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
#endif
8107
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    38
#ifdef TARGET_ARCH_arm
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    39
# include "bytes_arm.hpp"
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    40
#endif
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    41
#ifdef TARGET_ARCH_ppc
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    42
# include "bytes_ppc.hpp"
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    43
#endif
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    44
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// Input stream for reading .class file
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// The entire input stream is present in a buffer allocated by the caller.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// The caller is responsible for deallocating the buffer and for using
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// ResourceMarks appropriately when constructing streams.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
class ClassFileStream: public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  u1*   _buffer_start; // Buffer bottom
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  u1*   _buffer_end;   // Buffer top (one past last element)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  u1*   _current;      // Current buffer position
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  char* _source;       // Source of stream (directory name, ZIP/JAR archive name)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  bool  _need_verify;  // True if verification is on for the class file
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  void truncated_file_error(TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // Constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  ClassFileStream(u1* buffer, int length, char* source);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // Buffer access
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  u1* buffer() const           { return _buffer_start; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  int length() const           { return _buffer_end - _buffer_start; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  u1* current() const          { return _current; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  void set_current(u1* pos)    { _current = pos; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  char* source() const         { return _source; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  void set_verify(bool flag)   { _need_verify = flag; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  void check_truncated_file(bool b, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    if (b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
      truncated_file_error(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  void guarantee_more(int size, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    size_t remaining = (size_t)(_buffer_end - _current);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    unsigned int usize = (unsigned int)size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    check_truncated_file(usize > remaining, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // Read u1 from stream
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  u1 get_u1(TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  u1 get_u1_fast() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    return *_current++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // Read u2 from stream
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  u2 get_u2(TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  u2 get_u2_fast() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    u2 res = Bytes::get_Java_u2(_current);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    _current += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // Read u4 from stream
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  u4 get_u4(TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  u4 get_u4_fast() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    u4 res = Bytes::get_Java_u4(_current);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    _current += 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // Read u8 from stream
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  u8 get_u8(TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  u8 get_u8_fast() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    u8 res = Bytes::get_Java_u8(_current);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    _current += 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // Get direct pointer into stream at current position.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  // Returns NULL if length elements are not remaining. The caller is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // responsible for calling skip below if buffer contents is used.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  u1* get_u1_buffer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    return _current;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  u2* get_u2_buffer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    return (u2*) _current;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // Skip length u1 or u2 elements from stream
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  void skip_u1(int length, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  void skip_u1_fast(int length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    _current += length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  void skip_u2(int length, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  void skip_u2_fast(int length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    _current += 2 * length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
15102
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 8921
diff changeset
   136
  void skip_u4(int length, TRAPS);
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 8921
diff changeset
   137
  void skip_u4_fast(int length) {
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 8921
diff changeset
   138
    _current += 4 * length;
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 8921
diff changeset
   139
  }
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 8921
diff changeset
   140
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // Tells whether eos is reached
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  bool at_eos() const          { return _current == _buffer_end; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   144
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   145
#endif // SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP