hotspot/src/share/vm/runtime/reflectionUtils.cpp
author bobv
Tue, 29 Aug 2017 15:53:04 -0400
changeset 47100 17953cf82d51
parent 46329 53ccc37bda19
permissions -rw-r--r--
8186248: Allow more flexibility in selecting Heap % of available RAM Reviewed-by: dholmes, drwhite
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 39275
diff changeset
     2
 * Copyright (c) 1999, 2017, 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: 4571
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
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: 4571
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/javaClasses.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "memory/universe.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "runtime/reflectionUtils.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 39275
diff changeset
    30
KlassStream::KlassStream(InstanceKlass* klass, bool local_only,
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 13728
diff changeset
    31
                         bool classes_only, bool walk_defaults) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 13728
diff changeset
    32
  _klass = _base_klass = klass;
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 13728
diff changeset
    33
  _base_class_search_defaults = false;
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 13728
diff changeset
    34
  _defaults_checked = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  if (classes_only) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    36
    _interfaces = Universe::the_empty_klass_array();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    _interfaces = klass->transitive_interfaces();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  _interface_index = _interfaces->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  _local_only = local_only;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  _classes_only = classes_only;
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 13728
diff changeset
    43
  _walk_defaults = walk_defaults;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
bool KlassStream::eos() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  if (index() >= 0) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  if (_local_only) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  if (!_klass->is_interface() && _klass->super() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    // go up superclass chain (not for interfaces)
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 39275
diff changeset
    51
    _klass = InstanceKlass::cast(_klass->super());
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 13728
diff changeset
    52
  // Next for method walks, walk default methods
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 13728
diff changeset
    53
  } else if (_walk_defaults && (_defaults_checked == false)  && (_base_klass->default_methods() != NULL)) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 13728
diff changeset
    54
      _base_class_search_defaults = true;
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 13728
diff changeset
    55
      _klass = _base_klass;
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 13728
diff changeset
    56
      _defaults_checked = true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  } else {
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 13728
diff changeset
    58
    // Next walk transitive interfaces
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    if (_interface_index > 0) {
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 39275
diff changeset
    60
      _klass = InstanceKlass::cast(_interfaces->at(--_interface_index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  _index = length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  return eos();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
GrowableArray<FilteredField*> *FilteredFieldsMap::_filtered_fields =
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
    72
  new (ResourceObj::C_HEAP, mtInternal) GrowableArray<FilteredField*>(3,true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
void FilteredFieldsMap::initialize() {
39275
c6cea32506a4 8158237: JVMTI hides critical debug information for memory leak tracing
coleenp
parents: 37301
diff changeset
    76
  int offset = reflect_ConstantPool::oop_offset();
25057
f38210f84f8c 8031819: Remove legacy jdk checks and code
hseigel
parents: 20391
diff changeset
    77
  _filtered_fields->append(new FilteredField(SystemDictionary::reflect_ConstantPool_klass(), offset));
37301
a936b4e01afb 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 25057
diff changeset
    78
  offset = reflect_UnsafeStaticFieldAccessorImpl::base_offset();
25057
f38210f84f8c 8031819: Remove legacy jdk checks and code
hseigel
parents: 20391
diff changeset
    79
  _filtered_fields->append(new FilteredField(SystemDictionary::reflect_UnsafeStaticFieldAccessorImpl_klass(), offset));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
int FilteredFieldStream::field_count() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  int numflds = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  for (;!eos(); next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    numflds++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  return numflds;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
}