src/hotspot/share/oops/annotations.cpp
author coleenp
Wed, 24 Jul 2019 10:22:11 -0400
changeset 57511 00ae3b739184
parent 49036 bc92debe57e4
child 57823 efb2770e8288
permissions -rw-r--r--
8228485: JVM crashes when bootstrap method for condy triggers loading of class whose static initializer throws exception Summary: Add case for JVM_CONSTANT_Dynamic in error_message function. Reviewed-by: dholmes, shade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     1
/*
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
     2
 * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     4
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     8
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    13
 * accompanied this code).
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    14
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    18
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    21
 * questions.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    22
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    23
 */
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    24
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    25
#include "precompiled.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    26
#include "classfile/classLoaderData.hpp"
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
    27
#include "logging/log.hpp"
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    28
#include "memory/heapInspection.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    29
#include "memory/metadataFactory.hpp"
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
    30
#include "memory/metaspaceClosure.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    31
#include "memory/oopFactory.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    32
#include "oops/annotations.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    33
#include "oops/instanceKlass.hpp"
49036
bc92debe57e4 8197999: Accessors in typeArrayOopDesc should use new Access API
rkennke
parents: 47216
diff changeset
    34
#include "oops/typeArrayOop.inline.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    35
#include "utilities/ostream.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    36
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    37
// Allocate annotations in metadata area
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    38
Annotations* Annotations::allocate(ClassLoaderData* loader_data, TRAPS) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
    39
  return new (loader_data, size(), MetaspaceObj::AnnotationsType, THREAD) Annotations();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    40
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    41
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    42
// helper
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    43
void Annotations::free_contents(ClassLoaderData* loader_data, Array<AnnotationArray*>* p) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    44
  if (p != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    45
    for (int i = 0; i < p->length(); i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    46
      MetadataFactory::free_array<u1>(loader_data, p->at(i));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    47
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    48
    MetadataFactory::free_array<AnnotationArray*>(loader_data, p);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    49
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    50
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    51
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    52
void Annotations::deallocate_contents(ClassLoaderData* loader_data) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    53
  if (class_annotations() != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    54
    MetadataFactory::free_array<u1>(loader_data, class_annotations());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    55
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    56
  free_contents(loader_data, fields_annotations());
15097
9db149412e0e 8004823: Add VM support for type annotation reflection
stefank
parents: 13728
diff changeset
    57
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    58
  if (class_type_annotations() != NULL) {
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    59
    MetadataFactory::free_array<u1>(loader_data, class_type_annotations());
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    60
  }
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    61
  free_contents(loader_data, fields_type_annotations());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    62
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    63
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    64
// Copy annotations to JVM call or reflection to the java heap.
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    65
// The alternative to creating this array and adding to Java heap pressure
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    66
// is to have a hashtable of the already created typeArrayOops
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    67
typeArrayOop Annotations::make_java_array(AnnotationArray* annotations, TRAPS) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    68
  if (annotations != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    69
    int length = annotations->length();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    70
    typeArrayOop copy = oopFactory::new_byteArray(length, CHECK_NULL);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    71
    for (int i = 0; i< length; i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    72
      copy->byte_at_put(i, annotations->at(i));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    73
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    74
    return copy;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    75
  } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    76
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    77
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    78
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    79
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
    80
void Annotations::metaspace_pointers_do(MetaspaceClosure* it) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
    81
  log_trace(cds)("Iter(Annotations): %p", this);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
    82
  it->push(&_class_annotations);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
    83
  it->push(&_fields_annotations);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
    84
  it->push(&_class_type_annotations);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
    85
  it->push(&_fields_type_annotations); // FIXME: need a test case where _fields_type_annotations != NULL
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
    86
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    87
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    88
void Annotations::print_value_on(outputStream* st) const {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17858
diff changeset
    89
  st->print("Anotations(" INTPTR_FORMAT ")", p2i(this));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    90
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    91
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    92
#if INCLUDE_SERVICES
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    93
// Size Statistics
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    94
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    95
julong Annotations::count_bytes(Array<AnnotationArray*>* p) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    96
  julong bytes = 0;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    97
  if (p != NULL) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    98
    for (int i = 0; i < p->length(); i++) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    99
      bytes += KlassSizeStats::count_array(p->at(i));
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   100
    }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   101
    bytes += KlassSizeStats::count_array(p);
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   102
  }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   103
  return bytes;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   104
}
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   105
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   106
void Annotations::collect_statistics(KlassSizeStats *sz) const {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   107
  sz->_annotations_bytes = sz->count(this);
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   108
  sz->_class_annotations_bytes = sz->count(class_annotations());
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
   109
  sz->_class_type_annotations_bytes = sz->count(class_type_annotations());
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   110
  sz->_fields_annotations_bytes = count_bytes(fields_annotations());
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
   111
  sz->_fields_type_annotations_bytes = count_bytes(fields_type_annotations());
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   112
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   113
  sz->_annotations_bytes +=
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   114
      sz->_class_annotations_bytes +
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
   115
      sz->_class_type_annotations_bytes +
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   116
      sz->_fields_annotations_bytes +
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
   117
      sz->_fields_type_annotations_bytes;
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   118
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   119
  sz->_ro_bytes += sz->_annotations_bytes;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   120
}
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   121
#endif // INCLUDE_SERVICES
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   122
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   123
#define BULLET  " - "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   124
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   125
#ifndef PRODUCT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   126
void Annotations::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   127
  st->print(BULLET"class_annotations            "); class_annotations()->print_value_on(st);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   128
  st->print(BULLET"fields_annotations           "); fields_annotations()->print_value_on(st);
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
   129
  st->print(BULLET"class_type_annotations       "); class_type_annotations()->print_value_on(st);
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
   130
  st->print(BULLET"fields_type_annotations      "); fields_type_annotations()->print_value_on(st);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   131
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   132
#endif // PRODUCT