src/hotspot/share/oops/instanceMirrorKlass.inline.hpp
author stefank
Sat, 26 May 2018 06:59:49 +0200
changeset 50752 9d62da00bf15
parent 49982 9042ffe5b7fe
child 51444 3e5d28e6de32
permissions -rw-r--r--
8204540: Automatic oop closure devirtualization Reviewed-by: kbarrett, eosterlund
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
     1
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
     3
 *
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
     6
 * published by the Free Software Foundation.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
     7
 *
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
     8
 * This code is distributed in the hope that it will be useful, but WITHOUT
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
     9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    10
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    11
 * version 2 for more details (a copy is included in the LICENSE file that
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    12
 * accompanied this code).
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    13
 *
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License version
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    15
 * 2 along with this work; if not, write to the Free Software Foundation,
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    17
 *
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    18
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    19
 * or visit www.oracle.com if you need additional information or have any
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    20
 * questions.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    21
 *
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    22
 */
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    23
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    24
#ifndef SHARE_VM_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    25
#define SHARE_VM_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    26
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    27
#include "classfile/javaClasses.hpp"
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    28
#include "oops/instanceKlass.inline.hpp"
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    29
#include "oops/instanceMirrorKlass.hpp"
30880
efe35e08179f 8080746: Refactor oop iteration macros to be more general
sjohanss
parents: 30150
diff changeset
    30
#include "oops/klass.hpp"
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    31
#include "oops/oop.inline.hpp"
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    32
#include "utilities/debug.hpp"
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    33
#include "utilities/globalDefinitions.hpp"
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    34
#include "utilities/macros.hpp"
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    35
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
    36
template <typename T, class OopClosureType>
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
    37
void InstanceMirrorKlass::oop_oop_iterate_statics(oop obj, OopClosureType* closure) {
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    38
  T* p         = (T*)start_of_static_fields(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    39
  T* const end = p + java_lang_Class::static_oop_field_count(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    40
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    41
  for (; p < end; ++p) {
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
    42
    Devirtualizer::do_oop(closure, p);
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    43
  }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    44
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    45
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
    46
template <typename T, class OopClosureType>
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
    47
void InstanceMirrorKlass::oop_oop_iterate(oop obj, OopClosureType* closure) {
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
    48
  InstanceKlass::oop_oop_iterate<T>(obj, closure);
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    49
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
    50
  if (Devirtualizer::do_metadata(closure)) {
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    51
    Klass* klass = java_lang_Class::as_Klass(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    52
    // We'll get NULL for primitive mirrors.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    53
    if (klass != NULL) {
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 32606
diff changeset
    54
      if (klass->is_instance_klass() && InstanceKlass::cast(klass)->is_anonymous()) {
32606
fdaa30d06ada 8129417: Oop iteration clean-up to remove oop_ms_follow_contents
sjohanss
parents: 30880
diff changeset
    55
        // An anonymous class doesn't have its own class loader, so when handling
fdaa30d06ada 8129417: Oop iteration clean-up to remove oop_ms_follow_contents
sjohanss
parents: 30880
diff changeset
    56
        // the java mirror for an anonymous class we need to make sure its class
fdaa30d06ada 8129417: Oop iteration clean-up to remove oop_ms_follow_contents
sjohanss
parents: 30880
diff changeset
    57
        // loader data is claimed, this is done by calling do_cld explicitly.
fdaa30d06ada 8129417: Oop iteration clean-up to remove oop_ms_follow_contents
sjohanss
parents: 30880
diff changeset
    58
        // For non-anonymous classes the call to do_cld is made when the class
fdaa30d06ada 8129417: Oop iteration clean-up to remove oop_ms_follow_contents
sjohanss
parents: 30880
diff changeset
    59
        // loader itself is handled.
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
    60
        Devirtualizer::do_cld(closure, klass->class_loader_data());
32606
fdaa30d06ada 8129417: Oop iteration clean-up to remove oop_ms_follow_contents
sjohanss
parents: 30880
diff changeset
    61
      } else {
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
    62
        Devirtualizer::do_klass(closure, klass);
32606
fdaa30d06ada 8129417: Oop iteration clean-up to remove oop_ms_follow_contents
sjohanss
parents: 30880
diff changeset
    63
      }
fdaa30d06ada 8129417: Oop iteration clean-up to remove oop_ms_follow_contents
sjohanss
parents: 30880
diff changeset
    64
    } else {
48101
02f9be87cf5c 8179244: Assert failed in instanceMirrorKlass.inline.hpp
tschatzl
parents: 47216
diff changeset
    65
      // We would like to assert here (as below) that if klass has been NULL, then
02f9be87cf5c 8179244: Assert failed in instanceMirrorKlass.inline.hpp
tschatzl
parents: 47216
diff changeset
    66
      // this has been a mirror for a primitive type that we do not need to follow
02f9be87cf5c 8179244: Assert failed in instanceMirrorKlass.inline.hpp
tschatzl
parents: 47216
diff changeset
    67
      // as they are always strong roots.
02f9be87cf5c 8179244: Assert failed in instanceMirrorKlass.inline.hpp
tschatzl
parents: 47216
diff changeset
    68
      // However, we might get across a klass that just changed during CMS concurrent
02f9be87cf5c 8179244: Assert failed in instanceMirrorKlass.inline.hpp
tschatzl
parents: 47216
diff changeset
    69
      // marking if allocation occurred in the old generation.
02f9be87cf5c 8179244: Assert failed in instanceMirrorKlass.inline.hpp
tschatzl
parents: 47216
diff changeset
    70
      // This is benign here, as we keep alive all CLDs that were loaded during the
02f9be87cf5c 8179244: Assert failed in instanceMirrorKlass.inline.hpp
tschatzl
parents: 47216
diff changeset
    71
      // CMS concurrent phase in the class loading, i.e. they will be iterated over
02f9be87cf5c 8179244: Assert failed in instanceMirrorKlass.inline.hpp
tschatzl
parents: 47216
diff changeset
    72
      // and kept alive during remark.
02f9be87cf5c 8179244: Assert failed in instanceMirrorKlass.inline.hpp
tschatzl
parents: 47216
diff changeset
    73
      // assert(java_lang_Class::is_primitive(obj), "Sanity check");
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    74
    }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    75
  }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    76
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
    77
  oop_oop_iterate_statics<T>(obj, closure);
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    78
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    79
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
    80
template <typename T, class OopClosureType>
32606
fdaa30d06ada 8129417: Oop iteration clean-up to remove oop_ms_follow_contents
sjohanss
parents: 30880
diff changeset
    81
void InstanceMirrorKlass::oop_oop_iterate_reverse(oop obj, OopClosureType* closure) {
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
    82
  InstanceKlass::oop_oop_iterate_reverse<T>(obj, closure);
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    83
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
    84
  InstanceMirrorKlass::oop_oop_iterate_statics<T>(obj, closure);
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    85
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    86
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
    87
template <typename T, class OopClosureType>
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
    88
void InstanceMirrorKlass::oop_oop_iterate_statics_bounded(oop obj,
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
    89
                                                          OopClosureType* closure,
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
    90
                                                          MemRegion mr) {
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    91
  T* p   = (T*)start_of_static_fields(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    92
  T* end = p + java_lang_Class::static_oop_field_count(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    93
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    94
  T* const l   = (T*)mr.start();
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    95
  T* const h   = (T*)mr.end();
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    96
  assert(mask_bits((intptr_t)l, sizeof(T)-1) == 0 &&
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    97
         mask_bits((intptr_t)h, sizeof(T)-1) == 0,
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    98
         "bounded region must be properly aligned");
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
    99
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   100
  if (p < l) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   101
    p = l;
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   102
  }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   103
  if (end > h) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   104
    end = h;
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   105
  }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   106
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   107
  for (;p < end; ++p) {
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
   108
    Devirtualizer::do_oop(closure, p);
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   109
  }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   110
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   111
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
   112
template <typename T, class OopClosureType>
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
   113
void InstanceMirrorKlass::oop_oop_iterate_bounded(oop obj, OopClosureType* closure, MemRegion mr) {
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
   114
  InstanceKlass::oop_oop_iterate_bounded<T>(obj, closure, mr);
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   115
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
   116
  if (Devirtualizer::do_metadata(closure)) {
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   117
    if (mr.contains(obj)) {
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   118
      Klass* klass = java_lang_Class::as_Klass(obj);
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   119
      // We'll get NULL for primitive mirrors.
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   120
      if (klass != NULL) {
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
   121
        Devirtualizer::do_klass(closure, klass);
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   122
      }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   123
    }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   124
  }
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   125
50752
9d62da00bf15 8204540: Automatic oop closure devirtualization
stefank
parents: 49982
diff changeset
   126
  oop_oop_iterate_statics_bounded<T>(obj, closure, mr);
30150
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   127
}
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   128
d9c940aa42ef 8075955: Replace the macro based implementation of oop_oop_iterate with a template based solution
stefank
parents:
diff changeset
   129
#endif // SHARE_VM_OOPS_INSTANCEMIRRORKLASS_INLINE_HPP