hotspot/src/share/vm/oops/annotations.cpp
author drchase
Fri, 09 May 2014 16:50:54 -0400
changeset 24424 2658d7834c6e
parent 17858 c292f8791cca
child 46746 ea379ebb9447
permissions -rw-r--r--
8037816: Fix for 8036122 breaks build with Xcode5/clang Summary: Repaired or selectively disabled offending formats; future-proofed with additional checking Reviewed-by: kvn, jrose, stefank
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
/*
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17858
diff changeset
     2
 * Copyright (c) 2012, 2014, 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"
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    27
#include "memory/heapInspection.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    28
#include "memory/metadataFactory.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    29
#include "memory/oopFactory.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    30
#include "oops/annotations.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    31
#include "oops/instanceKlass.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    32
#include "utilities/ostream.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    33
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    34
// Allocate annotations in metadata area
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    35
Annotations* Annotations::allocate(ClassLoaderData* loader_data, TRAPS) {
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 15601
diff changeset
    36
  return new (loader_data, size(), true, MetaspaceObj::AnnotationType, THREAD) Annotations();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    37
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    38
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    39
// helper
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    40
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
    41
  if (p != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    42
    for (int i = 0; i < p->length(); i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    43
      MetadataFactory::free_array<u1>(loader_data, p->at(i));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    44
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    45
    MetadataFactory::free_array<AnnotationArray*>(loader_data, p);
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
}
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
void Annotations::deallocate_contents(ClassLoaderData* loader_data) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    50
  if (class_annotations() != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    51
    MetadataFactory::free_array<u1>(loader_data, class_annotations());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    52
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    53
  free_contents(loader_data, fields_annotations());
15097
9db149412e0e 8004823: Add VM support for type annotation reflection
stefank
parents: 13728
diff changeset
    54
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    55
  if (class_type_annotations() != NULL) {
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    56
    MetadataFactory::free_array<u1>(loader_data, class_type_annotations());
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    57
  }
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    58
  free_contents(loader_data, fields_type_annotations());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    59
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    60
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    61
// Copy annotations to JVM call or reflection to the java heap.
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    62
// The alternative to creating this array and adding to Java heap pressure
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    63
// 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
    64
typeArrayOop Annotations::make_java_array(AnnotationArray* annotations, TRAPS) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    65
  if (annotations != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    66
    int length = annotations->length();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    67
    typeArrayOop copy = oopFactory::new_byteArray(length, CHECK_NULL);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    68
    for (int i = 0; i< length; i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    69
      copy->byte_at_put(i, annotations->at(i));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    70
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    71
    return copy;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    72
  } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    73
    return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    74
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    75
}
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
void Annotations::print_value_on(outputStream* st) const {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 17858
diff changeset
    79
  st->print("Anotations(" INTPTR_FORMAT ")", p2i(this));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    80
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    81
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    82
#if INCLUDE_SERVICES
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    83
// Size Statistics
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    84
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    85
julong Annotations::count_bytes(Array<AnnotationArray*>* p) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    86
  julong bytes = 0;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    87
  if (p != NULL) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    88
    for (int i = 0; i < p->length(); i++) {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    89
      bytes += KlassSizeStats::count_array(p->at(i));
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    90
    }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    91
    bytes += KlassSizeStats::count_array(p);
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    92
  }
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    93
  return bytes;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    94
}
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    95
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    96
void Annotations::collect_statistics(KlassSizeStats *sz) const {
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    97
  sz->_annotations_bytes = sz->count(this);
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
    98
  sz->_class_annotations_bytes = sz->count(class_annotations());
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
    99
  sz->_class_type_annotations_bytes = sz->count(class_type_annotations());
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   100
  sz->_fields_annotations_bytes = count_bytes(fields_annotations());
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
   101
  sz->_fields_type_annotations_bytes = count_bytes(fields_type_annotations());
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   102
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   103
  sz->_annotations_bytes +=
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   104
      sz->_class_annotations_bytes +
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
   105
      sz->_class_type_annotations_bytes +
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   106
      sz->_fields_annotations_bytes +
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
   107
      sz->_fields_type_annotations_bytes;
15437
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   108
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   109
  sz->_ro_bytes += sz->_annotations_bytes;
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   110
}
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   111
#endif // INCLUDE_SERVICES
eabd4555d072 6479360: PrintClassHistogram improvements
acorn
parents: 15097
diff changeset
   112
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   113
#define BULLET  " - "
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   114
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   115
#ifndef PRODUCT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   116
void Annotations::print_on(outputStream* st) const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   117
  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
   118
  st->print(BULLET"fields_annotations           "); fields_annotations()->print_value_on(st);
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
   119
  st->print(BULLET"class_type_annotations       "); class_type_annotations()->print_value_on(st);
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15437
diff changeset
   120
  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
   121
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   122
#endif // PRODUCT