src/hotspot/share/classfile/classFileStream.cpp
author redestad
Thu, 20 Dec 2018 19:44:08 +0100
changeset 53091 5bf5b773fc41
parent 47216 71c04702a3d5
child 54042 6dd6f988b4e4
permissions -rw-r--r--
8215555: TieredCompilation C2 threads can excessively block handshakes Reviewed-by: kvn, neliasso, rehn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 34666
diff changeset
     2
 * Copyright (c) 1997, 2016, 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
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "classfile/classFileStream.hpp"
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37248
diff changeset
    27
#include "classfile/classLoader.hpp"
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37248
diff changeset
    28
#include "classfile/dictionary.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "classfile/vmSymbols.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 34666
diff changeset
    30
#include "memory/resourceArea.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    32
const bool ClassFileStream::verify = true;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    33
const bool ClassFileStream::no_verification = false;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    34
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    35
void ClassFileStream::truncated_file_error(TRAPS) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  THROW_MSG(vmSymbols::java_lang_ClassFormatError(), "Truncated class file");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    39
ClassFileStream::ClassFileStream(const u1* buffer,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    40
                                 int length,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    41
                                 const char* source,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    42
                                 bool verify_stream) :
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    43
  _buffer_start(buffer),
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    44
  _buffer_end(buffer + length),
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    45
  _current(buffer),
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    46
  _source(source),
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    47
  _need_verify(verify_stream) {}
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    48
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    49
const u1* ClassFileStream::clone_buffer() const {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    50
  u1* const new_buffer_start = NEW_RESOURCE_ARRAY(u1, length());
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    51
  memcpy(new_buffer_start, _buffer_start, length());
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    52
  return new_buffer_start;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    55
const char* const ClassFileStream::clone_source() const {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    56
  const char* const src = source();
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    57
  char* source_copy = NULL;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    58
  if (src != NULL) {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    59
    size_t source_len = strlen(src);
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    60
    source_copy = NEW_RESOURCE_ARRAY(char, source_len + 1);
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    61
    strncpy(source_copy, src, source_len + 1);
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
  return source_copy;
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    64
}
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    65
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    66
// Caller responsible for ResourceMark
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    67
// clone stream with a rewound position
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    68
const ClassFileStream* ClassFileStream::clone() const {
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    69
  const u1* const new_buffer_start = clone_buffer();
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    70
  return new ClassFileStream(new_buffer_start,
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    71
                             length(),
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    72
                             clone_source(),
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    73
                             need_verify());
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    74
}
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    75
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    76
u1 ClassFileStream::get_u1(TRAPS) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  if (_need_verify) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    guarantee_more(1, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    assert(1 <= _buffer_end - _current, "buffer overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  return *_current++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    85
u2 ClassFileStream::get_u2(TRAPS) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  if (_need_verify) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    guarantee_more(2, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    assert(2 <= _buffer_end - _current, "buffer overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  }
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    91
  const u1* tmp = _current;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  _current += 2;
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    93
  return Bytes::get_Java_u2((address)tmp);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
    96
u4 ClassFileStream::get_u4(TRAPS) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  if (_need_verify) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    guarantee_more(4, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    assert(4 <= _buffer_end - _current, "buffer overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  }
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   102
  const u1* tmp = _current;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  _current += 4;
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   104
  return Bytes::get_Java_u4((address)tmp);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   107
u8 ClassFileStream::get_u8(TRAPS) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  if (_need_verify) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    guarantee_more(8, CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    assert(8 <= _buffer_end - _current, "buffer overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   113
  const u1* tmp = _current;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  _current += 8;
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   115
  return Bytes::get_Java_u8((address)tmp);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   118
void ClassFileStream::skip_u1(int length, TRAPS) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  if (_need_verify) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    guarantee_more(length, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  _current += length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   125
void ClassFileStream::skip_u2(int length, TRAPS) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  if (_need_verify) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    guarantee_more(length * 2, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  _current += length * 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
}
15102
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 7397
diff changeset
   131
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 26419
diff changeset
   132
void ClassFileStream::skip_u4(int length, TRAPS) const {
15102
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 7397
diff changeset
   133
  if (_need_verify) {
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 7397
diff changeset
   134
    guarantee_more(length * 4, CHECK);
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 7397
diff changeset
   135
  }
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 7397
diff changeset
   136
  _current += length * 4;
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 7397
diff changeset
   137
}
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37248
diff changeset
   138
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37248
diff changeset
   139
uint64_t ClassFileStream::compute_fingerprint() const {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37248
diff changeset
   140
  int classfile_size = length();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37248
diff changeset
   141
  int classfile_crc = ClassLoader::crc32(0, (const char*)buffer(), length());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37248
diff changeset
   142
  uint64_t fingerprint = (uint64_t(classfile_size) << 32) | uint64_t(uint32_t(classfile_crc));
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37248
diff changeset
   143
  assert(fingerprint != 0, "must not be zero");
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37248
diff changeset
   144
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37248
diff changeset
   145
  return fingerprint;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents: 37248
diff changeset
   146
}