src/hotspot/share/gc/shared/oopStorageSet.cpp
author zgu
Mon, 09 Sep 2019 11:43:16 -0400
changeset 59284 88502b1cf76f
parent 57828 35db8fba55f9
permissions -rw-r--r--
8230765: Implement nmethod barrier for x86_32 platforms Reviewed-by: rkennke, eosterlund
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57828
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
     1
/*
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
     4
 *
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
     7
 * published by the Free Software Foundation.
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
     8
 *
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    13
 * accompanied this code).
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    14
 *
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    18
 *
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    21
 * questions.
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    22
 *
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    23
 */
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    24
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    25
#include "precompiled.hpp"
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    26
#include "gc/shared/oopStorage.hpp"
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    27
#include "gc/shared/oopStorageSet.hpp"
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    28
#include "runtime/mutex.hpp"
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    29
#include "runtime/os.hpp"
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    30
#include "utilities/debug.hpp"
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    31
#include "utilities/globalDefinitions.hpp"
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    32
#include "utilities/macros.hpp"
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    33
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    34
// +1 for NULL singular entry.
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    35
OopStorage* OopStorageSet::storages[all_count + 1] = {};
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    36
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    37
static Mutex* make_oopstorage_mutex(const char* storage_name,
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    38
                                    const char* kind,
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    39
                                    int rank) {
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    40
  char name[256];
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    41
  os::snprintf(name, sizeof(name), "%s %s lock", storage_name, kind);
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    42
  return new PaddedMutex(rank, name, true, Mutex::_safepoint_check_never);
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    43
}
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    44
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    45
static OopStorage* make_oopstorage(const char* name) {
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    46
  Mutex* alloc = make_oopstorage_mutex(name, "alloc", Mutex::oopstorage);
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    47
  Mutex* active = make_oopstorage_mutex(name, "active", Mutex::oopstorage - 1);
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    48
  return new OopStorage(name, alloc, active);
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    49
}
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    50
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    51
void OopStorageSet::initialize() {
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    52
  storages[jni_global_index]        = make_oopstorage("JNI global");
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    53
  storages[vm_global_index]         = make_oopstorage("VM global");
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    54
  storages[jni_weak_index]          = make_oopstorage("JNI weak");
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    55
  storages[vm_weak_index]           = make_oopstorage("VM weak");
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    56
  storages[string_table_weak_index] = make_oopstorage("StringTable weak");
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    57
  storages[resolved_method_table_weak_index] =
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    58
    make_oopstorage("ResolvedMethodTable weak");
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    59
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    60
  // Ensure we have all of them.
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    61
  STATIC_ASSERT(all_count == 6);
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    62
  assert(storages[singular_index] == NULL, "postcondition");
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    63
#ifdef ASSERT
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    64
  for (uint i = all_start; i < all_end; ++i) {
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    65
    assert(storages[i] != NULL, "postcondition");
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    66
  }
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    67
#endif // ASSERT
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    68
}
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    69
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    70
void oopstorage_init() {
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    71
  OopStorageSet::initialize();
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    72
}
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    73
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    74
#ifdef ASSERT
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    75
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    76
void OopStorageSet::verify_initialized(uint index) {
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    77
  assert(storages[index] != NULL, "oopstorage_init not yet called");
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    78
}
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    79
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    80
void OopStorageSet::Iterator::verify_nonsingular() const {
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    81
  assert(_category != singular, "precondition");
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    82
}
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    83
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    84
void OopStorageSet::Iterator::verify_category_match(const Iterator& other) const {
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    85
  verify_nonsingular();
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    86
  assert(_category == other._category, "precondition");
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    87
}
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    88
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    89
void OopStorageSet::Iterator::verify_dereferenceable() const {
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    90
  verify_nonsingular();
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    91
  assert(!is_end(), "precondition");
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    92
}
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    93
35db8fba55f9 8227054: ServiceThread needs to know about all OopStorage objects
kbarrett
parents:
diff changeset
    94
#endif // ASSERT