src/hotspot/share/oops/annotations.cpp
author ihse
Thu, 19 Oct 2017 11:59:52 +0200
changeset 47659 a8e9aff89f7b
parent 47216 71c04702a3d5
child 49036 bc92debe57e4
permissions -rw-r--r--
8189608: Remove duplicated jni.h Reviewed-by: erikj, dholmes, coleenp
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"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    34
#include "utilities/ostream.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    35
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    36
// Allocate annotations in metadata area
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    37
Annotations* Annotations::allocate(ClassLoaderData* loader_data, TRAPS) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
    38
  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
    39
}
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
// helper
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    42
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
    43
  if (p != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    44
    for (int i = 0; i < p->length(); i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    45
      MetadataFactory::free_array<u1>(loader_data, p->at(i));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    46
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    47
    MetadataFactory::free_array<AnnotationArray*>(loader_data, p);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    48
  }
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
void Annotations::deallocate_contents(ClassLoaderData* loader_data) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    52
  if (class_annotations() != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    53
    MetadataFactory::free_array<u1>(loader_data, class_annotations());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    54
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    55
  free_contents(loader_data, fields_annotations());
15097
9db149412e0e 8004823: Add VM support for type annotation reflection
stefank
parents: 13728
diff changeset
    56
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    57
  if (class_type_annotations() != NULL) {
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    58
    MetadataFactory::free_array<u1>(loader_data, class_type_annotations());
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    59
  }
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    60
  free_contents(loader_data, fields_type_annotations());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    61
}
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
// Copy annotations to JVM call or reflection to the java heap.
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    64
// The alternative to creating this array and adding to Java heap pressure
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    65
// 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
    66
typeArrayOop Annotations::make_java_array(AnnotationArray* annotations, TRAPS) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    67
  if (annotations != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    68
    int length = annotations->length();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    69
    typeArrayOop copy = oopFactory::new_byteArray(length, CHECK_NULL);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    70
    for (int i = 0; i< length; i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    71
      copy->byte_at_put(i, annotations->at(i));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    72
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    73
    return copy;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    74
  } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    75
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    76
  }
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
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
    79
void Annotations::metaspace_pointers_do(MetaspaceClosure* it) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
    80
  log_trace(cds)("Iter(Annotations): %p", this);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
    81
  it->push(&_class_annotations);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
    82
  it->push(&_fields_annotations);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
    83
  it->push(&_class_type_annotations);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 24424
diff changeset
    84
  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
    85
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    86
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    87
void Annotations::print_value_on(outputStream* st) const {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17858
diff changeset
    88
  st->print("Anotations(" INTPTR_FORMAT ")", p2i(this));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    89
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    90
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    91
#if INCLUDE_SERVICES
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    92
// Size Statistics
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    93
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    94
julong Annotations::count_bytes(Array<AnnotationArray*>* p) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    95
  julong bytes = 0;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    96
  if (p != NULL) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    97
    for (int i = 0; i < p->length(); i++) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    98
      bytes += KlassSizeStats::count_array(p->at(i));
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    99
    }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   100
    bytes += KlassSizeStats::count_array(p);
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   101
  }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   102
  return bytes;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   103
}
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   104
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   105
void Annotations::collect_statistics(KlassSizeStats *sz) const {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   106
  sz->_annotations_bytes = sz->count(this);
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   107
  sz->_class_annotations_bytes = sz->count(class_annotations());
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
   108
  sz->_class_type_annotations_bytes = sz->count(class_type_annotations());
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   109
  sz->_fields_annotations_bytes = count_bytes(fields_annotations());
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
   110
  sz->_fields_type_annotations_bytes = count_bytes(fields_type_annotations());
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   111
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   112
  sz->_annotations_bytes +=
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   113
      sz->_class_annotations_bytes +
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
   114
      sz->_class_type_annotations_bytes +
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   115
      sz->_fields_annotations_bytes +
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
   116
      sz->_fields_type_annotations_bytes;
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   117
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   118
  sz->_ro_bytes += sz->_annotations_bytes;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   119
}
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   120
#endif // INCLUDE_SERVICES
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   121
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   122
#define BULLET  " - "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   123
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   124
#ifndef PRODUCT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   125
void Annotations::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   126
  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
   127
  st->print(BULLET"fields_annotations           "); fields_annotations()->print_value_on(st);
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
   128
  st->print(BULLET"class_type_annotations       "); class_type_annotations()->print_value_on(st);
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
   129
  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
   130
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   131
#endif // PRODUCT