test/hotspot/gtest/gc/shared/test_oopStorage.cpp
author kbarrett
Thu, 03 May 2018 17:36:50 -0400
changeset 49977 9f758f0bb058
parent 49711 4a7addb5762c
child 50209 2fdce199fcb9
permissions -rw-r--r--
8200557: OopStorage parallel iteration scales poorly Summary: Change representation of sequence of all blocks for better scaling. Reviewed-by: coleenp, eosterlund
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
     1
/*
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
     4
 *
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
     8
 *
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    13
 * accompanied this code).
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    14
 *
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    18
 *
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    21
 * questions.
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    22
 */
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    23
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    24
#include "precompiled.hpp"
48816
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents: 48806
diff changeset
    25
#include "gc/shared/oopStorage.inline.hpp"
3495d6050efe 8194898: Move OopStorage inline definitions to an .inline.hpp
kbarrett
parents: 48806
diff changeset
    26
#include "gc/shared/oopStorageParState.inline.hpp"
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    27
#include "gc/shared/workgroup.hpp"
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    28
#include "memory/allocation.inline.hpp"
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    29
#include "memory/resourceArea.hpp"
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    30
#include "metaprogramming/conditional.hpp"
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    31
#include "metaprogramming/enableIf.hpp"
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    32
#include "runtime/handles.inline.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49392
diff changeset
    33
#include "runtime/interfaceSupport.inline.hpp"
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    34
#include "runtime/mutex.hpp"
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    35
#include "runtime/mutexLocker.hpp"
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    36
#include "runtime/thread.hpp"
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    37
#include "runtime/vm_operations.hpp"
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    38
#include "runtime/vmThread.hpp"
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    39
#include "utilities/align.hpp"
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    40
#include "utilities/ostream.hpp"
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    41
#include "utilities/quickSort.hpp"
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    42
#include "unittest.hpp"
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    43
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    44
// --- FIXME: Disable some tests on 32bit Windows, because SafeFetch
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    45
//     (which is used by allocation_status) doesn't currently provide
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    46
//     protection in the context where gtests are run; see JDK-8185734.
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    47
#ifdef _WIN32
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    48
#define DISABLE_GARBAGE_ALLOCATION_STATUS_TESTS
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    49
#endif
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    50
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    51
// Access storage internals.
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    52
class OopStorage::TestAccess : public AllStatic {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    53
public:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    54
  typedef OopStorage::Block Block;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    55
  typedef OopStorage::BlockList BlockList;
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
    56
  typedef OopStorage::BlockArray BlockArray;
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    57
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
    58
  static BlockArray& active_array(const OopStorage& storage) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
    59
    return *storage._active_array;
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    60
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    61
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    62
  static BlockList& allocate_list(OopStorage& storage) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    63
    return storage._allocate_list;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    64
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    65
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    66
  static const BlockList& allocate_list(const OopStorage& storage) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    67
    return storage._allocate_list;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    68
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    69
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    70
  static Mutex* allocate_mutex(const OopStorage& storage) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    71
    return storage._allocate_mutex;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    72
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    73
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
    74
  static bool reduce_deferred_updates(OopStorage& storage) {
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
    75
    return storage.reduce_deferred_updates();
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
    76
  }
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
    77
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    78
  static bool block_is_empty(const Block& block) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    79
    return block.is_empty();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    80
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    81
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    82
  static bool block_is_full(const Block& block) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    83
    return block.is_full();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    84
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    85
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    86
  static unsigned block_allocation_count(const Block& block) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    87
    uintx bitmask = block.allocated_bitmask();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    88
    unsigned count = 0;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    89
    for ( ; bitmask != 0; bitmask >>= 1) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    90
      if ((bitmask & 1) != 0) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    91
        ++count;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    92
      }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    93
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    94
    return count;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    95
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    96
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    97
  static size_t memory_per_block() {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    98
    return Block::allocation_size();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
    99
  }
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   100
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   101
  static void block_array_set_block_count(BlockArray* blocks, size_t count) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   102
    blocks->_block_count = count;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   103
  }
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   104
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   105
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   106
typedef OopStorage::TestAccess TestAccess;
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   107
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   108
// The "Oop" prefix is to avoid collision with similar opto names when
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   109
// building with precompiled headers, or for consistency with that
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   110
// workaround.  There really should be an opto namespace.
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   111
typedef TestAccess::Block OopBlock;
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   112
typedef TestAccess::BlockList OopBlockList;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   113
typedef TestAccess::BlockArray OopBlockArray;
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   114
48806
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
   115
// Using EXPECT_EQ can't use NULL directly. Otherwise AIX build breaks.
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
   116
const OopBlock* const NULL_BLOCK = NULL;
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
   117
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   118
static size_t list_length(const OopBlockList& list) {
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   119
  size_t result = 0;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   120
  for (const OopBlock* block = list.chead();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   121
       block != NULL;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   122
       block = list.next(*block)) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   123
    ++result;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   124
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   125
  return result;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   126
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   127
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   128
static void clear_list(OopBlockList& list) {
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   129
  OopBlock* next;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   130
  for (OopBlock* block = list.head(); block != NULL; block = next) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   131
    next = list.next(*block);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   132
    list.unlink(*block);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   133
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   134
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   135
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   136
static bool is_list_empty(const OopBlockList& list) {
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   137
  return list.chead() == NULL;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   138
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   139
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   140
static bool process_deferred_updates(OopStorage& storage) {
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   141
  MutexLockerEx ml(TestAccess::allocate_mutex(storage), Mutex::_no_safepoint_check_flag);
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   142
  bool result = false;
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   143
  while (TestAccess::reduce_deferred_updates(storage)) {
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   144
    result = true;
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   145
  }
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   146
  return result;
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   147
}
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   148
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   149
static void release_entry(OopStorage& storage, oop* entry, bool process_deferred = true) {
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   150
  *entry = NULL;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   151
  storage.release(entry);
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   152
  if (process_deferred) {
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   153
    process_deferred_updates(storage);
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   154
  }
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   155
}
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   156
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   157
static size_t empty_block_count(const OopStorage& storage) {
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   158
  const OopBlockList& list = TestAccess::allocate_list(storage);
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   159
  size_t count = 0;
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   160
  for (const OopBlock* block = list.ctail();
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   161
       (block != NULL) && block->is_empty();
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   162
       ++count, block = list.prev(*block))
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   163
  {}
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   164
  return count;
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   165
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   166
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   167
static size_t active_count(const OopStorage& storage) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   168
  return TestAccess::active_array(storage).block_count();
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   169
}
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   170
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   171
static OopBlock* active_head(const OopStorage& storage) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   172
  OopBlockArray& ba = TestAccess::active_array(storage);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   173
  size_t count = ba.block_count();
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   174
  if (count == 0) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   175
    return NULL;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   176
  } else {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   177
    return ba.at(count - 1);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   178
  }
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   179
}
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   180
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   181
class OopStorageTest : public ::testing::Test {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   182
public:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   183
  OopStorageTest();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   184
  ~OopStorageTest();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   185
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   186
  Mutex _allocate_mutex;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   187
  Mutex _active_mutex;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   188
  OopStorage _storage;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   189
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   190
  static const int _active_rank = Mutex::leaf - 1;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   191
  static const int _allocate_rank = Mutex::leaf;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   192
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   193
  class CountingIterateClosure;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   194
  template<bool is_const> class VM_CountAtSafepoint;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   195
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   196
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   197
OopStorageTest::OopStorageTest() :
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   198
  _allocate_mutex(_allocate_rank,
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   199
                  "test_OopStorage_allocate",
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   200
                  false,
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   201
                  Mutex::_safepoint_check_never),
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   202
  _active_mutex(_active_rank,
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   203
                "test_OopStorage_active",
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   204
                false,
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   205
                Mutex::_safepoint_check_never),
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   206
  _storage("Test Storage", &_allocate_mutex, &_active_mutex)
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   207
{ }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   208
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   209
OopStorageTest::~OopStorageTest() {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   210
  clear_list(TestAccess::allocate_list(_storage));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   211
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   212
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   213
class OopStorageTestWithAllocation : public OopStorageTest {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   214
public:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   215
  OopStorageTestWithAllocation();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   216
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   217
  static const size_t _max_entries = 1000;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   218
  oop* _entries[_max_entries];
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   219
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   220
  class VM_DeleteBlocksAtSafepoint;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   221
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   222
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   223
OopStorageTestWithAllocation::OopStorageTestWithAllocation() {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   224
  for (size_t i = 0; i < _max_entries; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   225
    _entries[i] = _storage.allocate();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   226
    EXPECT_TRUE(_entries[i] != NULL);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   227
    EXPECT_EQ(i + 1, _storage.allocation_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   228
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   229
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   230
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   231
const size_t OopStorageTestWithAllocation::_max_entries;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   232
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   233
class OopStorageTestWithAllocation::VM_DeleteBlocksAtSafepoint
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   234
  : public VM_GTestExecuteAtSafepoint {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   235
public:
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   236
  VM_DeleteBlocksAtSafepoint(OopStorage* storage) : _storage(storage) {}
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   237
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   238
  void doit() {
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   239
    _storage->delete_empty_blocks_safepoint();
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   240
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   241
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   242
private:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   243
  OopStorage* _storage;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   244
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   245
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   246
static bool is_allocate_list_sorted(const OopStorage& storage) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   247
  // The allocate_list isn't strictly sorted.  Rather, all empty
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   248
  // blocks are segregated to the end of the list.
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   249
  const OopBlockList& list = TestAccess::allocate_list(storage);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   250
  const OopBlock* block = list.ctail();
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   251
  for ( ; (block != NULL) && block->is_empty(); block = list.prev(*block)) {}
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   252
  for ( ; block != NULL; block = list.prev(*block)) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   253
    if (block->is_empty()) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   254
      return false;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   255
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   256
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   257
  return true;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   258
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   259
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   260
static size_t total_allocation_count(const OopStorage& storage) {
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   261
  size_t total_count = 0;
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   262
  const OopBlockArray& ba = TestAccess::active_array(storage);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   263
  size_t limit = active_count(storage);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   264
  for (size_t i = 0; i < limit; ++i) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   265
    total_count += TestAccess::block_allocation_count(*ba.at(i));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   266
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   267
  return total_count;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   268
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   269
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   270
TEST_VM_F(OopStorageTest, allocate_one) {
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   271
  EXPECT_EQ(0u, active_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   272
  EXPECT_TRUE(is_list_empty(TestAccess::allocate_list(_storage)));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   273
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   274
  oop* ptr = _storage.allocate();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   275
  EXPECT_TRUE(ptr != NULL);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   276
  EXPECT_EQ(1u, _storage.allocation_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   277
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   278
  EXPECT_EQ(1u, active_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   279
  EXPECT_EQ(1u, _storage.block_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   280
  EXPECT_EQ(1u, list_length(TestAccess::allocate_list(_storage)));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   281
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   282
  EXPECT_EQ(0u, empty_block_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   283
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   284
  const OopBlock* block = TestAccess::allocate_list(_storage).chead();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   285
  EXPECT_NE(block, (OopBlock*)NULL);
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   286
  EXPECT_EQ(block, active_head(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   287
  EXPECT_FALSE(TestAccess::block_is_empty(*block));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   288
  EXPECT_FALSE(TestAccess::block_is_full(*block));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   289
  EXPECT_EQ(1u, TestAccess::block_allocation_count(*block));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   290
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   291
  release_entry(_storage, ptr);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   292
  EXPECT_EQ(0u, _storage.allocation_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   293
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   294
  EXPECT_EQ(1u, active_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   295
  EXPECT_EQ(1u, _storage.block_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   296
  EXPECT_EQ(1u, list_length(TestAccess::allocate_list(_storage)));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   297
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   298
  EXPECT_EQ(1u, empty_block_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   299
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   300
  const OopBlock* new_block = TestAccess::allocate_list(_storage).chead();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   301
  EXPECT_EQ(block, new_block);
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   302
  EXPECT_EQ(block, active_head(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   303
  EXPECT_TRUE(TestAccess::block_is_empty(*block));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   304
  EXPECT_FALSE(TestAccess::block_is_full(*block));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   305
  EXPECT_EQ(0u, TestAccess::block_allocation_count(*block));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   306
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   307
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   308
TEST_VM_F(OopStorageTest, allocation_count) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   309
  static const size_t max_entries = 1000;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   310
  oop* entries[max_entries];
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   311
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   312
  OopBlockList& allocate_list = TestAccess::allocate_list(_storage);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   313
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   314
  EXPECT_EQ(0u, active_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   315
  EXPECT_EQ(0u, _storage.block_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   316
  EXPECT_TRUE(is_list_empty(allocate_list));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   317
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   318
  size_t allocated = 0;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   319
  for ( ; allocated < max_entries; ++allocated) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   320
    EXPECT_EQ(allocated, _storage.allocation_count());
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   321
    if (active_count(_storage) != 0) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   322
      EXPECT_EQ(1u, active_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   323
      EXPECT_EQ(1u, _storage.block_count());
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   324
      const OopBlock& block = *TestAccess::active_array(_storage).at(0);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   325
      EXPECT_EQ(allocated, TestAccess::block_allocation_count(block));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   326
      if (TestAccess::block_is_full(block)) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   327
        break;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   328
      } else {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   329
        EXPECT_FALSE(is_list_empty(allocate_list));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   330
        EXPECT_EQ(&block, allocate_list.chead());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   331
      }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   332
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   333
    entries[allocated] = _storage.allocate();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   334
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   335
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   336
  EXPECT_EQ(allocated, _storage.allocation_count());
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   337
  EXPECT_EQ(1u, active_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   338
  EXPECT_EQ(1u, _storage.block_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   339
  EXPECT_TRUE(is_list_empty(allocate_list));
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   340
  const OopBlock& block = *TestAccess::active_array(_storage).at(0);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   341
  EXPECT_TRUE(TestAccess::block_is_full(block));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   342
  EXPECT_EQ(allocated, TestAccess::block_allocation_count(block));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   343
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   344
  for (size_t i = 0; i < allocated; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   345
    release_entry(_storage, entries[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   346
    size_t remaining = allocated - (i + 1);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   347
    EXPECT_EQ(remaining, TestAccess::block_allocation_count(block));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   348
    EXPECT_EQ(remaining, _storage.allocation_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   349
    EXPECT_FALSE(is_list_empty(allocate_list));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   350
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   351
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   352
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   353
TEST_VM_F(OopStorageTest, allocate_many) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   354
  static const size_t max_entries = 1000;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   355
  oop* entries[max_entries];
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   356
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   357
  OopBlockList& allocate_list = TestAccess::allocate_list(_storage);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   358
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   359
  EXPECT_EQ(0u, empty_block_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   360
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   361
  entries[0] = _storage.allocate();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   362
  ASSERT_TRUE(entries[0] != NULL);
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   363
  EXPECT_EQ(1u, active_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   364
  EXPECT_EQ(1u, _storage.block_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   365
  EXPECT_EQ(1u, list_length(allocate_list));
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   366
  EXPECT_EQ(0u, empty_block_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   367
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   368
  const OopBlock* block = TestAccess::active_array(_storage).at(0);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   369
  EXPECT_EQ(1u, TestAccess::block_allocation_count(*block));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   370
  EXPECT_EQ(block, allocate_list.chead());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   371
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   372
  for (size_t i = 1; i < max_entries; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   373
    entries[i] = _storage.allocate();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   374
    EXPECT_EQ(i + 1, _storage.allocation_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   375
    ASSERT_TRUE(entries[i] != NULL);
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   376
    EXPECT_EQ(0u, empty_block_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   377
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   378
    if (block == NULL) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   379
      ASSERT_FALSE(is_list_empty(allocate_list));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   380
      EXPECT_EQ(1u, list_length(allocate_list));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   381
      block = allocate_list.chead();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   382
      EXPECT_EQ(1u, TestAccess::block_allocation_count(*block));
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   383
      EXPECT_EQ(block, active_head(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   384
    } else if (TestAccess::block_is_full(*block)) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   385
      EXPECT_TRUE(is_list_empty(allocate_list));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   386
      block = NULL;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   387
    } else {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   388
      EXPECT_FALSE(is_list_empty(allocate_list));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   389
      EXPECT_EQ(block, allocate_list.chead());
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   390
      EXPECT_EQ(block, active_head(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   391
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   392
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   393
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   394
  if (block != NULL) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   395
    EXPECT_NE(0u, TestAccess::block_allocation_count(*block));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   396
    EXPECT_FALSE(is_list_empty(allocate_list));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   397
    EXPECT_EQ(block, allocate_list.chead());
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   398
    EXPECT_EQ(block, active_head(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   399
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   400
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   401
  for (size_t i = 0; i < max_entries; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   402
    release_entry(_storage, entries[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   403
    EXPECT_TRUE(is_allocate_list_sorted(_storage));
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   404
    EXPECT_EQ(max_entries - (i + 1), total_allocation_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   405
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   406
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   407
  EXPECT_EQ(active_count(_storage), list_length(allocate_list));
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   408
  EXPECT_EQ(active_count(_storage), _storage.block_count());
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   409
  EXPECT_EQ(active_count(_storage), empty_block_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   410
  for (const OopBlock* block = allocate_list.chead();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   411
       block != NULL;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   412
       block = allocate_list.next(*block)) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   413
    EXPECT_TRUE(TestAccess::block_is_empty(*block));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   414
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   415
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   416
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   417
TEST_VM_F(OopStorageTestWithAllocation, random_release) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   418
  static const size_t step = 11;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   419
  ASSERT_NE(0u, _max_entries % step); // max_entries and step are mutually prime
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   420
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   421
  EXPECT_EQ(0u, empty_block_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   422
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   423
  OopBlockList& allocate_list = TestAccess::allocate_list(_storage);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   424
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   425
  EXPECT_EQ(_max_entries, total_allocation_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   426
  EXPECT_GE(1u, list_length(allocate_list));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   427
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   428
  // Release all entries in "random" order.
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   429
  size_t released = 0;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   430
  for (size_t i = 0; released < _max_entries; i = (i + step) % _max_entries) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   431
    if (_entries[i] != NULL) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   432
      release_entry(_storage, _entries[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   433
      _entries[i] = NULL;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   434
      ++released;
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   435
      EXPECT_EQ(_max_entries - released, total_allocation_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   436
      EXPECT_TRUE(is_allocate_list_sorted(_storage));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   437
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   438
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   439
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   440
  EXPECT_EQ(active_count(_storage), list_length(allocate_list));
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   441
  EXPECT_EQ(active_count(_storage), _storage.block_count());
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   442
  EXPECT_EQ(0u, total_allocation_count(_storage));
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   443
  EXPECT_EQ(list_length(allocate_list), empty_block_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   444
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   445
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   446
TEST_VM_F(OopStorageTestWithAllocation, random_allocate_release) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   447
  static const size_t release_step = 11;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   448
  static const size_t allocate_step = 5;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   449
  ASSERT_NE(0u, _max_entries % release_step); // max_entries and step are mutually prime
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   450
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   451
  EXPECT_EQ(0u, empty_block_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   452
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   453
  OopBlockList& allocate_list = TestAccess::allocate_list(_storage);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   454
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   455
  EXPECT_EQ(_max_entries, total_allocation_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   456
  EXPECT_GE(1u, list_length(allocate_list));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   457
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   458
  // Release all entries in "random" order, "randomly" interspersed
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   459
  // with additional allocations.
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   460
  size_t released = 0;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   461
  size_t total_released = 0;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   462
  for (size_t i = 0; released < _max_entries; i = (i + release_step) % _max_entries) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   463
    if (_entries[i] != NULL) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   464
      release_entry(_storage, _entries[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   465
      _entries[i] = NULL;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   466
      ++released;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   467
      ++total_released;
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   468
      EXPECT_EQ(_max_entries - released, total_allocation_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   469
      EXPECT_TRUE(is_allocate_list_sorted(_storage));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   470
      if (total_released % allocate_step == 0) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   471
        _entries[i] = _storage.allocate();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   472
        --released;
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   473
        EXPECT_EQ(_max_entries - released, total_allocation_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   474
        EXPECT_TRUE(is_allocate_list_sorted(_storage));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   475
      }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   476
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   477
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   478
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   479
  EXPECT_EQ(active_count(_storage), list_length(allocate_list));
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   480
  EXPECT_EQ(active_count(_storage), _storage.block_count());
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
   481
  EXPECT_EQ(0u, total_allocation_count(_storage));
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   482
  EXPECT_EQ(list_length(allocate_list), empty_block_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   483
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   484
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   485
template<bool sorted>
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   486
class OopStorageTestBlockRelease : public OopStorageTestWithAllocation {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   487
public:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   488
  void SetUp() {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   489
    size_t nrelease = _max_entries / 2;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   490
    oop** to_release = NEW_C_HEAP_ARRAY(oop*, nrelease, mtInternal);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   491
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   492
    for (size_t i = 0; i < nrelease; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   493
      to_release[i] = _entries[2 * i];
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   494
      *to_release[i] = NULL;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   495
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   496
    if (sorted) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   497
      QuickSort::sort(to_release, nrelease, PointerCompare(), false);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   498
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   499
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   500
    _storage.release(to_release, nrelease);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   501
    EXPECT_EQ(_max_entries - nrelease, _storage.allocation_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   502
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   503
    for (size_t i = 0; i < nrelease; ++i) {
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   504
      release_entry(_storage, _entries[2 * i + 1], false);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   505
      EXPECT_EQ(_max_entries - nrelease - (i + 1), _storage.allocation_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   506
    }
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   507
    EXPECT_TRUE(process_deferred_updates(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   508
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   509
    EXPECT_EQ(_storage.block_count(), empty_block_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   510
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   511
    FREE_C_HEAP_ARRAY(oop*, to_release);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   512
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   513
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   514
  struct PointerCompare {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   515
    int operator()(const void* p, const void* q) const {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   516
      return (p < q) ? -1 : int(p != q);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   517
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   518
  };
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   519
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   520
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   521
typedef OopStorageTestBlockRelease<true> OopStorageTestBlockReleaseSorted;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   522
typedef OopStorageTestBlockRelease<false> OopStorageTestBlockReleaseUnsorted;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   523
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   524
TEST_VM_F(OopStorageTestBlockReleaseSorted, block_release) {}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   525
TEST_VM_F(OopStorageTestBlockReleaseUnsorted, block_release) {}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   526
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   527
#ifndef DISABLE_GARBAGE_ALLOCATION_STATUS_TESTS
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   528
TEST_VM_F(OopStorageTest, invalid_pointer) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   529
  {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   530
    char* mem = NEW_C_HEAP_ARRAY(char, 1000, mtInternal);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   531
    oop* ptr = reinterpret_cast<oop*>(align_down(mem + 250, sizeof(oop)));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   532
    // Predicate returns false for some malloc'ed block.
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   533
    EXPECT_EQ(OopStorage::INVALID_ENTRY, _storage.allocation_status(ptr));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   534
    FREE_C_HEAP_ARRAY(char, mem);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   535
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   536
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   537
  {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   538
    oop obj;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   539
    oop* ptr = &obj;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   540
    // Predicate returns false for some "random" location.
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   541
    EXPECT_EQ(OopStorage::INVALID_ENTRY, _storage.allocation_status(ptr));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   542
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   543
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   544
#endif // DISABLE_GARBAGE_ALLOCATION_STATUS_TESTS
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   545
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 49030
diff changeset
   546
class OopStorageTest::CountingIterateClosure {
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   547
public:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   548
  size_t _const_count;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   549
  size_t _const_non_null;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   550
  size_t _non_const_count;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   551
  size_t _non_const_non_null;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   552
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   553
  void do_oop(const oop* ptr) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   554
    ++_const_count;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   555
    if (*ptr != NULL) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   556
      ++_const_non_null;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   557
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   558
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   559
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   560
  void do_oop(oop* ptr) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   561
    ++_non_const_count;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   562
    if (*ptr != NULL) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   563
      ++_non_const_non_null;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   564
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   565
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   566
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   567
  CountingIterateClosure() :
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   568
    _const_count(0),
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   569
    _const_non_null(0),
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   570
    _non_const_count(0),
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   571
    _non_const_non_null(0)
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   572
  {}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   573
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   574
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   575
template<bool is_const>
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   576
class OopStorageTest::VM_CountAtSafepoint : public VM_GTestExecuteAtSafepoint {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   577
public:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   578
  typedef typename Conditional<is_const,
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   579
                               const OopStorage,
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   580
                               OopStorage>::type Storage;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   581
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   582
  VM_CountAtSafepoint(Storage* storage, CountingIterateClosure* cl) :
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   583
    _storage(storage), _cl(cl)
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   584
  {}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   585
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   586
  void doit() { _storage->oops_do(_cl); }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   587
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   588
private:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   589
  Storage* _storage;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   590
  CountingIterateClosure* _cl;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   591
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   592
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   593
TEST_VM_F(OopStorageTest, simple_iterate) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   594
  // Dummy oop value.
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   595
  intptr_t dummy_oop_value = 0xbadbeaf;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   596
  oop dummy_oop = reinterpret_cast<oopDesc*>(&dummy_oop_value);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   597
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   598
  const size_t max_entries = 1000;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   599
  oop* entries[max_entries];
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   600
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   601
  size_t allocated = 0;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   602
  size_t entries_with_values = 0;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   603
  for (size_t i = 0; i < max_entries; i += 10) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   604
    for ( ; allocated < i; ++allocated) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   605
      entries[allocated] = _storage.allocate();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   606
      ASSERT_TRUE(entries[allocated] != NULL);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   607
      if ((allocated % 3) != 0) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   608
        *entries[allocated] = dummy_oop;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   609
        ++entries_with_values;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   610
      }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   611
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   612
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   613
    {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   614
      CountingIterateClosure cl;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   615
      VM_CountAtSafepoint<false> op(&_storage, &cl);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   616
      {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   617
        ThreadInVMfromNative invm(JavaThread::current());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   618
        VMThread::execute(&op);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   619
      }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   620
      EXPECT_EQ(allocated, cl._non_const_count);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   621
      EXPECT_EQ(entries_with_values, cl._non_const_non_null);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   622
      EXPECT_EQ(0u, cl._const_count);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   623
      EXPECT_EQ(0u, cl._const_non_null);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   624
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   625
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   626
    {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   627
      CountingIterateClosure cl;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   628
      VM_CountAtSafepoint<true> op(&_storage, &cl);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   629
      {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   630
        ThreadInVMfromNative invm(JavaThread::current());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   631
        VMThread::execute(&op);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   632
      }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   633
      EXPECT_EQ(allocated, cl._const_count);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   634
      EXPECT_EQ(entries_with_values, cl._const_non_null);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   635
      EXPECT_EQ(0u, cl._non_const_count);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   636
      EXPECT_EQ(0u, cl._non_const_non_null);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   637
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   638
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   639
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   640
  while (allocated > 0) {
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   641
    release_entry(_storage, entries[--allocated], false);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   642
  }
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   643
  process_deferred_updates(_storage);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   644
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   645
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   646
class OopStorageTestIteration : public OopStorageTestWithAllocation {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   647
public:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   648
  static const size_t _max_workers = 2;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   649
  unsigned char _states[_max_workers][_max_entries];
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   650
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   651
  static const unsigned char mark_released  = 1u << 0;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   652
  static const unsigned char mark_invalid   = 1u << 1;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   653
  static const unsigned char mark_const     = 1u << 2;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   654
  static const unsigned char mark_non_const = 1u << 3;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   655
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   656
  virtual void SetUp() {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   657
    OopStorageTestWithAllocation::SetUp();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   658
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   659
    memset(_states, 0, sizeof(_states));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   660
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   661
    size_t initial_release = 0;
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   662
    for ( ; empty_block_count(_storage) < 2; ++initial_release) {
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   663
      ASSERT_GT(_max_entries, initial_release);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   664
      release_entry(_storage, _entries[initial_release]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   665
      _states[0][initial_release] = mark_released;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   666
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   667
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   668
    for (size_t i = initial_release; i < _max_entries; i += 3) {
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   669
      release_entry(_storage, _entries[i], false);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   670
      _states[0][i] = mark_released;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   671
    }
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
   672
    process_deferred_updates(_storage);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   673
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   674
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   675
  class VerifyState;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   676
  class VerifyFn;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   677
  template<bool is_const> class VM_Verify;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   678
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   679
  class VerifyClosure;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   680
  class VM_VerifyUsingOopsDo;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   681
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   682
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   683
const unsigned char OopStorageTestIteration::mark_released;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   684
const unsigned char OopStorageTestIteration::mark_invalid;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   685
const unsigned char OopStorageTestIteration::mark_const;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   686
const unsigned char OopStorageTestIteration::mark_non_const;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   687
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 49030
diff changeset
   688
class OopStorageTestIteration::VerifyState {
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   689
public:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   690
  unsigned char _expected_mark;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   691
  const oop* const* _entries;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   692
  unsigned char (&_states)[_max_workers][_max_entries];
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   693
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   694
  VerifyState(unsigned char expected_mark,
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   695
              const oop* const* entries,
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   696
              unsigned char (&states)[_max_workers][_max_entries]) :
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   697
    _expected_mark(expected_mark),
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   698
    _entries(entries),
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   699
    _states(states)
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   700
  { }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   701
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   702
  bool update(const oop* ptr, uint worker_id, unsigned char mark) const {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   703
    size_t index = 0;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   704
    bool found = find_entry(ptr, &index);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   705
    EXPECT_TRUE(found);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   706
    EXPECT_GT(_max_entries, index);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   707
    EXPECT_GT(_max_workers, worker_id);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   708
    if (!found) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   709
      return false;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   710
    } else if (index >= _max_entries) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   711
      return false;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   712
    } else if (worker_id >= _max_workers) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   713
      return false;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   714
    } else {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   715
      EXPECT_EQ(0, _states[worker_id][index]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   716
      if (_states[worker_id][index] != 0) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   717
        _states[worker_id][index] |= mark_invalid;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   718
        return false;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   719
      } else {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   720
        _states[worker_id][index] |= mark;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   721
        return true;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   722
      }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   723
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   724
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   725
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   726
  void check() const {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   727
    for (size_t i = 0; i < _max_entries; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   728
      unsigned char mark = 0;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   729
      for (size_t w = 0; w < _max_workers; ++w) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   730
        if (mark == 0) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   731
          mark = _states[w][i];
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   732
        } else {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   733
          EXPECT_EQ(0u, _states[w][i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   734
        }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   735
      }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   736
      if (mark == 0) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   737
        EXPECT_NE(0u, mark);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   738
      } else if ((mark & mark_released) != 0) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   739
        EXPECT_EQ(mark_released, mark);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   740
      } else {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   741
        EXPECT_EQ(_expected_mark, mark);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   742
      }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   743
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   744
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   745
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   746
private:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   747
  bool find_entry(const oop* ptr, size_t* index) const {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   748
    for (size_t i = 0; i < _max_entries; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   749
      if (ptr == _entries[i]) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   750
        *index = i;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   751
        return true;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   752
      }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   753
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   754
    return false;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   755
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   756
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   757
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 49030
diff changeset
   758
class OopStorageTestIteration::VerifyFn {
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   759
public:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   760
  VerifyFn(VerifyState* state, uint worker_id = 0) :
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   761
    _state(state),
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   762
    _worker_id(worker_id)
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   763
  {}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   764
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   765
  bool operator()(      oop* ptr) const {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   766
    return _state->update(ptr, _worker_id, mark_non_const);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   767
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   768
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   769
  bool operator()(const oop* ptr) const {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   770
    return _state->update(ptr, _worker_id, mark_const);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   771
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   772
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   773
private:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   774
  VerifyState* _state;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   775
  uint _worker_id;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   776
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   777
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 49030
diff changeset
   778
class OopStorageTestIteration::VerifyClosure {
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   779
public:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   780
  VerifyClosure(VerifyState* state, uint worker_id = 0) :
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   781
    _state(state),
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   782
    _worker_id(worker_id)
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   783
  {}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   784
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   785
  void do_oop(oop* ptr) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   786
    _state->update(ptr, _worker_id, mark_non_const);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   787
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   788
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   789
  void do_oop(const oop* ptr) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   790
    _state->update(ptr, _worker_id, mark_const);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   791
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   792
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   793
private:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   794
  VerifyState* _state;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   795
  uint _worker_id;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   796
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   797
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   798
const size_t OopStorageTestIteration::_max_workers;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   799
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   800
template<bool is_const>
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   801
class OopStorageTestIteration::VM_Verify : public VM_GTestExecuteAtSafepoint {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   802
public:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   803
  typedef typename Conditional<is_const,
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   804
                               const OopStorage,
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   805
                               OopStorage>::type Storage;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   806
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   807
  VM_Verify(Storage* storage, VerifyState* vstate) :
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   808
    _storage(storage), _vstate(vstate), _result(false)
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   809
  {}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   810
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   811
  void doit() {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   812
    VerifyFn verifier(_vstate);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   813
    _result = _storage->iterate_safepoint(verifier);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   814
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   815
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   816
  bool result() const { return _result; }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   817
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   818
private:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   819
  Storage* _storage;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   820
  VerifyState* _vstate;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   821
  bool _result;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   822
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   823
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   824
class OopStorageTestIteration::VM_VerifyUsingOopsDo : public VM_GTestExecuteAtSafepoint {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   825
public:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   826
  VM_VerifyUsingOopsDo(OopStorage* storage, VerifyState* vstate) :
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   827
    _storage(storage), _vstate(vstate)
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   828
  {}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   829
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   830
  void doit() {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   831
    VerifyClosure verifier(_vstate);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   832
    _storage->oops_do(&verifier);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   833
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   834
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   835
private:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   836
  OopStorage* _storage;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   837
  VerifyState* _vstate;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   838
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   839
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   840
TEST_VM_F(OopStorageTestIteration, iterate_safepoint) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   841
  VerifyState vstate(mark_non_const, _entries, _states);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   842
  VM_Verify<false> op(&_storage, &vstate);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   843
  {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   844
    ThreadInVMfromNative invm(JavaThread::current());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   845
    VMThread::execute(&op);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   846
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   847
  EXPECT_TRUE(op.result());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   848
  vstate.check();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   849
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   850
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   851
TEST_VM_F(OopStorageTestIteration, const_iterate_safepoint) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   852
  VerifyState vstate(mark_const, _entries, _states);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   853
  VM_Verify<true> op(&_storage, &vstate);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   854
  {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   855
    ThreadInVMfromNative invm(JavaThread::current());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   856
    VMThread::execute(&op);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   857
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   858
  EXPECT_TRUE(op.result());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   859
  vstate.check();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   860
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   861
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   862
TEST_VM_F(OopStorageTestIteration, oops_do) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   863
  VerifyState vstate(mark_non_const, _entries, _states);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   864
  VM_VerifyUsingOopsDo op(&_storage, &vstate);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   865
  {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   866
    ThreadInVMfromNative invm(JavaThread::current());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   867
    VMThread::execute(&op);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   868
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   869
  vstate.check();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   870
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   871
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   872
class OopStorageTestParIteration : public OopStorageTestIteration {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   873
public:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   874
  WorkGang* workers();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   875
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   876
  class VM_ParStateVerify;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   877
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   878
  template<bool concurrent, bool is_const> class Task;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   879
  template<bool concurrent, bool is_const> class TaskUsingOopsDo;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   880
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   881
private:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   882
  static WorkGang* _workers;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   883
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   884
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   885
WorkGang* OopStorageTestParIteration::_workers = NULL;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   886
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   887
WorkGang* OopStorageTestParIteration::workers() {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   888
  if (_workers == NULL) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   889
    _workers = new WorkGang("OopStorageTestParIteration workers",
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   890
                            _max_workers,
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   891
                            false,
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   892
                            false);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   893
    _workers->initialize_workers();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   894
    _workers->update_active_workers(_max_workers);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   895
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   896
  return _workers;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   897
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   898
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   899
template<bool concurrent, bool is_const>
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   900
class OopStorageTestParIteration::Task : public AbstractGangTask {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   901
  typedef OopStorage::ParState<concurrent, is_const> StateType;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   902
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   903
  typedef typename Conditional<is_const,
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   904
                               const OopStorage,
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   905
                               OopStorage>::type Storage;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   906
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   907
public:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   908
  Task(const char* name, Storage* storage, VerifyState* vstate) :
49030
1817d118ff66 8198267: Allow GCId::current_raw() calls from non-NamedThreads
pliden
parents: 48886
diff changeset
   909
    AbstractGangTask(name),
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   910
    _state(storage),
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   911
    _vstate(vstate)
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   912
  {}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   913
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   914
  virtual void work(uint worker_id) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   915
    VerifyFn verifier(_vstate, worker_id);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   916
    _state.iterate(verifier);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   917
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   918
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   919
private:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   920
  StateType _state;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   921
  VerifyState* _vstate;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   922
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   923
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   924
template<bool concurrent, bool is_const>
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   925
class OopStorageTestParIteration::TaskUsingOopsDo : public AbstractGangTask {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   926
public:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   927
  TaskUsingOopsDo(const char* name, OopStorage* storage, VerifyState* vstate) :
49030
1817d118ff66 8198267: Allow GCId::current_raw() calls from non-NamedThreads
pliden
parents: 48886
diff changeset
   928
    AbstractGangTask(name),
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   929
    _state(storage),
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   930
    _vstate(vstate)
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   931
  {}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   932
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   933
  virtual void work(uint worker_id) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   934
    VerifyClosure verifier(_vstate, worker_id);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   935
    _state.oops_do(&verifier);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   936
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   937
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   938
private:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   939
  OopStorage::ParState<concurrent, is_const> _state;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   940
  VerifyState* _vstate;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   941
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   942
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   943
class OopStorageTestParIteration::VM_ParStateVerify : public VM_GTestExecuteAtSafepoint {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   944
public:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   945
  VM_ParStateVerify(WorkGang* workers, AbstractGangTask* task) :
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   946
    _workers(workers), _task(task)
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   947
  {}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   948
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   949
  void doit() {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   950
    _workers->run_task(_task);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   951
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   952
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   953
private:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   954
  WorkGang* _workers;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   955
  AbstractGangTask* _task;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   956
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   957
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   958
TEST_VM_F(OopStorageTestParIteration, par_state_safepoint_iterate) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   959
  VerifyState vstate(mark_non_const, _entries, _states);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   960
  Task<false, false> task("test", &_storage, &vstate);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   961
  VM_ParStateVerify op(workers(), &task);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   962
  {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   963
    ThreadInVMfromNative invm(JavaThread::current());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   964
    VMThread::execute(&op);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   965
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   966
  vstate.check();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   967
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   968
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   969
TEST_VM_F(OopStorageTestParIteration, par_state_safepoint_const_iterate) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   970
  VerifyState vstate(mark_const, _entries, _states);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   971
  Task<false, true> task("test", &_storage, &vstate);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   972
  VM_ParStateVerify op(workers(), &task);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   973
  {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   974
    ThreadInVMfromNative invm(JavaThread::current());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   975
    VMThread::execute(&op);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   976
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   977
  vstate.check();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   978
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   979
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   980
TEST_VM_F(OopStorageTestParIteration, par_state_safepoint_oops_do) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   981
  VerifyState vstate(mark_non_const, _entries, _states);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   982
  TaskUsingOopsDo<false, false> task("test", &_storage, &vstate);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   983
  VM_ParStateVerify op(workers(), &task);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   984
  {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   985
    ThreadInVMfromNative invm(JavaThread::current());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   986
    VMThread::execute(&op);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   987
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   988
  vstate.check();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   989
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   990
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   991
TEST_VM_F(OopStorageTestParIteration, par_state_safepoint_const_oops_do) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   992
  VerifyState vstate(mark_const, _entries, _states);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   993
  TaskUsingOopsDo<false, true> task("test", &_storage, &vstate);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   994
  VM_ParStateVerify op(workers(), &task);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   995
  {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   996
    ThreadInVMfromNative invm(JavaThread::current());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   997
    VMThread::execute(&op);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   998
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
   999
  vstate.check();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1000
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1001
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1002
TEST_VM_F(OopStorageTestParIteration, par_state_concurrent_iterate) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1003
  VerifyState vstate(mark_non_const, _entries, _states);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1004
  Task<true, false> task("test", &_storage, &vstate);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1005
  workers()->run_task(&task);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1006
  vstate.check();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1007
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1008
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1009
TEST_VM_F(OopStorageTestParIteration, par_state_concurrent_const_iterate) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1010
  VerifyState vstate(mark_const, _entries, _states);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1011
  Task<true, true> task("test", &_storage, &vstate);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1012
  workers()->run_task(&task);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1013
  vstate.check();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1014
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1015
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1016
TEST_VM_F(OopStorageTestParIteration, par_state_concurrent_oops_do) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1017
  VerifyState vstate(mark_non_const, _entries, _states);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1018
  TaskUsingOopsDo<true, false> task("test", &_storage, &vstate);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1019
  workers()->run_task(&task);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1020
  vstate.check();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1021
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1022
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1023
TEST_VM_F(OopStorageTestParIteration, par_state_concurrent_const_oops_do) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1024
  VerifyState vstate(mark_const, _entries, _states);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1025
  TaskUsingOopsDo<true, true> task("test", &_storage, &vstate);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1026
  workers()->run_task(&task);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1027
  vstate.check();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1028
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1029
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1030
TEST_VM_F(OopStorageTestWithAllocation, delete_empty_blocks_safepoint) {
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1031
  size_t initial_active_size = active_count(_storage);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1032
  EXPECT_EQ(initial_active_size, _storage.block_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1033
  ASSERT_LE(3u, initial_active_size); // Need at least 3 blocks for test
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1034
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1035
  for (size_t i = 0; empty_block_count(_storage) < 3; ++i) {
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1036
    ASSERT_GT(_max_entries, i);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1037
    release_entry(_storage, _entries[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1038
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1039
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1040
  EXPECT_EQ(initial_active_size, active_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1041
  EXPECT_EQ(initial_active_size, _storage.block_count());
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1042
  EXPECT_EQ(3u, empty_block_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1043
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1044
  {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1045
    ThreadInVMfromNative invm(JavaThread::current());
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1046
    VM_DeleteBlocksAtSafepoint op(&_storage);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1047
    VMThread::execute(&op);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1048
  }
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1049
  EXPECT_EQ(0u, empty_block_count(_storage));
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1050
  EXPECT_EQ(initial_active_size - 3, active_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1051
  EXPECT_EQ(initial_active_size - 3, _storage.block_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1052
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1053
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1054
TEST_VM_F(OopStorageTestWithAllocation, delete_empty_blocks_concurrent) {
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1055
  size_t initial_active_size = active_count(_storage);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1056
  EXPECT_EQ(initial_active_size, _storage.block_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1057
  ASSERT_LE(3u, initial_active_size); // Need at least 3 blocks for test
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1058
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1059
  for (size_t i = 0; empty_block_count(_storage) < 3; ++i) {
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1060
    ASSERT_GT(_max_entries, i);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1061
    release_entry(_storage, _entries[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1062
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1063
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1064
  EXPECT_EQ(initial_active_size, active_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1065
  EXPECT_EQ(initial_active_size, _storage.block_count());
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1066
  EXPECT_EQ(3u, empty_block_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1067
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1068
  _storage.delete_empty_blocks_concurrent();
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1069
  EXPECT_EQ(0u, empty_block_count(_storage));
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1070
  EXPECT_EQ(initial_active_size - 3, active_count(_storage));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1071
  EXPECT_EQ(initial_active_size - 3, _storage.block_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1072
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1073
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1074
TEST_VM_F(OopStorageTestWithAllocation, allocation_status) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1075
  oop* retained = _entries[200];
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1076
  oop* released = _entries[300];
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1077
  oop* garbage = reinterpret_cast<oop*>(1024 * 1024);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1078
  release_entry(_storage, released);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1079
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1080
  EXPECT_EQ(OopStorage::ALLOCATED_ENTRY, _storage.allocation_status(retained));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1081
  EXPECT_EQ(OopStorage::UNALLOCATED_ENTRY, _storage.allocation_status(released));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1082
#ifndef DISABLE_GARBAGE_ALLOCATION_STATUS_TESTS
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1083
  EXPECT_EQ(OopStorage::INVALID_ENTRY, _storage.allocation_status(garbage));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1084
#endif
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1085
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1086
  for (size_t i = 0; i < _max_entries; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1087
    if ((_entries[i] != retained) && (_entries[i] != released)) {
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1088
      // Leave deferred release updates to block deletion.
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1089
      release_entry(_storage, _entries[i], false);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1090
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1091
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1092
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1093
  {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1094
    ThreadInVMfromNative invm(JavaThread::current());
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1095
    VM_DeleteBlocksAtSafepoint op(&_storage);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1096
    VMThread::execute(&op);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1097
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1098
  EXPECT_EQ(OopStorage::ALLOCATED_ENTRY, _storage.allocation_status(retained));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1099
#ifndef DISABLE_GARBAGE_ALLOCATION_STATUS_TESTS
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1100
  EXPECT_EQ(OopStorage::INVALID_ENTRY, _storage.allocation_status(released));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1101
  EXPECT_EQ(OopStorage::INVALID_ENTRY, _storage.allocation_status(garbage));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1102
#endif // DISABLE_GARBAGE_ALLOCATION_STATUS_TESTS
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1103
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1104
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1105
TEST_VM_F(OopStorageTest, usage_info) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1106
  size_t goal_blocks = 5;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1107
  oop* entries[1000];
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1108
  size_t allocated = 0;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1109
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1110
  EXPECT_EQ(0u, _storage.block_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1111
  // There is non-block overhead, so always some usage.
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1112
  EXPECT_LT(0u, _storage.total_memory_usage());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1113
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1114
  while (_storage.block_count() < goal_blocks) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1115
    size_t this_count = _storage.block_count();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1116
    while (_storage.block_count() == this_count) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1117
      ASSERT_GT(ARRAY_SIZE(entries), allocated);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1118
      entries[allocated] = _storage.allocate();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1119
      ASSERT_TRUE(entries[allocated] != NULL);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1120
      ++allocated;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1121
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1122
    EXPECT_NE(0u, _storage.block_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1123
    EXPECT_NE(0u, _storage.total_memory_usage());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1124
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1125
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1126
  EXPECT_LT(TestAccess::memory_per_block() * _storage.block_count(),
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1127
            _storage.total_memory_usage());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1128
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1129
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1130
#ifndef PRODUCT
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1131
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1132
TEST_VM_F(OopStorageTestWithAllocation, print_storage) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1133
  // Release the first 1/2
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1134
  for (size_t i = 0; i < (_max_entries / 2); ++i) {
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1135
    // Deferred updates don't affect print output.
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1136
    release_entry(_storage, _entries[i], false);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1137
    _entries[i] = NULL;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1138
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1139
  // Release every other remaining
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1140
  for (size_t i = _max_entries / 2; i < _max_entries; i += 2) {
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1141
    // Deferred updates don't affect print output.
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1142
    release_entry(_storage, _entries[i], false);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1143
    _entries[i] = NULL;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1144
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1145
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1146
  size_t expected_entries = _max_entries / 4;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1147
  EXPECT_EQ(expected_entries, _storage.allocation_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1148
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1149
  size_t entries_per_block = BitsPerWord;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1150
  size_t expected_blocks = (_max_entries + entries_per_block - 1) / entries_per_block;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1151
  EXPECT_EQ(expected_blocks, _storage.block_count());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1152
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1153
  double expected_usage = (100.0 * expected_entries) / (expected_blocks * entries_per_block);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1154
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1155
  {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1156
    ResourceMark rm;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1157
    stringStream expected_st;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1158
    expected_st.print("Test Storage: " SIZE_FORMAT
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1159
                      " entries in " SIZE_FORMAT
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1160
                      " blocks (%.F%%), " SIZE_FORMAT " bytes",
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1161
                      expected_entries,
48886
e1d09bd56d2d 8196083: Avoid locking in OopStorage::release
kbarrett
parents: 48816
diff changeset
  1162
                      expected_blocks,
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1163
                      expected_usage,
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1164
                      _storage.total_memory_usage());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1165
    stringStream st;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1166
    _storage.print_on(&st);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1167
    EXPECT_STREQ(expected_st.as_string(), st.as_string());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1168
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1169
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1170
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1171
#endif // !PRODUCT
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1172
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1173
class OopStorageBlockCollectionTest : public ::testing::Test {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1174
protected:
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1175
  OopStorageBlockCollectionTest() {
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1176
    for (size_t i = 0; i < nvalues; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1177
      values[i] = OopBlock::new_block(pseudo_owner());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1178
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1179
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1180
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1181
  ~OopStorageBlockCollectionTest() {
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1182
    for (size_t i = 0; i < nvalues; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1183
      OopBlock::delete_block(*values[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1184
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1185
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1186
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1187
public:
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1188
  static const size_t nvalues = 10;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1189
  OopBlock* values[nvalues];
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1190
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1191
private:
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1192
  // The only thing we actually care about is the address of the owner.
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1193
  static const size_t pseudo_owner_size = sizeof(OopStorage) / sizeof(void*);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1194
  static const void* const _pseudo_owner[pseudo_owner_size];
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1195
  static const OopStorage* pseudo_owner() {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1196
    return reinterpret_cast<const OopStorage*>(&_pseudo_owner);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1197
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1198
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1199
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1200
const size_t OopStorageBlockCollectionTest::nvalues;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1201
const void* const OopStorageBlockCollectionTest::_pseudo_owner[] = {};
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1202
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1203
class OopStorageBlockListTest : public OopStorageBlockCollectionTest {};
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1204
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1205
TEST_F(OopStorageBlockListTest, empty_list) {
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1206
  OopBlockList list(&OopBlock::get_allocate_entry);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1207
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1208
  EXPECT_TRUE(is_list_empty(list));
48806
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1209
  EXPECT_EQ(NULL_BLOCK, list.head());
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1210
  EXPECT_EQ(NULL_BLOCK, list.chead());
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1211
  EXPECT_EQ(NULL_BLOCK, list.ctail());
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1212
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1213
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1214
TEST_F(OopStorageBlockListTest, push_back) {
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1215
  OopBlockList list(&OopBlock::get_allocate_entry);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1216
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1217
  for (size_t i = 0; i < nvalues; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1218
    list.push_back(*values[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1219
    EXPECT_FALSE(is_list_empty(list));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1220
    EXPECT_EQ(list.ctail(), values[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1221
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1222
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1223
  EXPECT_EQ(list.chead(), list.head());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1224
  EXPECT_EQ(list.chead(), values[0]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1225
  EXPECT_EQ(list.ctail(), values[nvalues - 1]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1226
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1227
  const OopBlock* block = list.chead();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1228
  for (size_t i = 0; i < nvalues; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1229
    EXPECT_EQ(block, values[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1230
    block = list.next(*block);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1231
  }
48806
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1232
  EXPECT_EQ(NULL_BLOCK, block);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1233
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1234
  block = list.ctail();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1235
  for (size_t i = 0; i < nvalues; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1236
    EXPECT_EQ(block, values[nvalues - i - 1]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1237
    block = list.prev(*block);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1238
  }
48806
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1239
  EXPECT_EQ(NULL_BLOCK, block);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1240
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1241
  clear_list(list);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1242
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1243
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1244
TEST_F(OopStorageBlockListTest, push_front) {
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1245
  OopBlockList list(&OopBlock::get_allocate_entry);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1246
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1247
  for (size_t i = 0; i < nvalues; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1248
    list.push_front(*values[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1249
    EXPECT_FALSE(is_list_empty(list));
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1250
    EXPECT_EQ(list.head(), values[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1251
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1252
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1253
  EXPECT_EQ(list.chead(), list.head());
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1254
  EXPECT_EQ(list.chead(), values[nvalues - 1]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1255
  EXPECT_EQ(list.ctail(), values[0]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1256
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1257
  const OopBlock* block = list.chead();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1258
  for (size_t i = 0; i < nvalues; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1259
    EXPECT_EQ(block, values[nvalues - i - 1]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1260
    block = list.next(*block);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1261
  }
48806
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1262
  EXPECT_EQ(NULL_BLOCK, block);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1263
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1264
  block = list.ctail();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1265
  for (size_t i = 0; i < nvalues; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1266
    EXPECT_EQ(block, values[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1267
    block = list.prev(*block);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1268
  }
48806
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1269
  EXPECT_EQ(NULL_BLOCK, block);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1270
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1271
  clear_list(list);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1272
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1273
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1274
class OopStorageBlockListTestWithList : public OopStorageBlockListTest {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1275
public:
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1276
  OopStorageBlockListTestWithList() : list(&OopBlock::get_allocate_entry) {
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1277
    for (size_t i = 0; i < nvalues; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1278
      list.push_back(*values[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1279
    }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1280
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1281
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1282
  ~OopStorageBlockListTestWithList() {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1283
    clear_list(list);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1284
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1285
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1286
  OopBlockList list;
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1287
};
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1288
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1289
TEST_F(OopStorageBlockListTestWithList, unlink_front) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1290
  EXPECT_EQ(list.chead(), values[0]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1291
  EXPECT_EQ(list.ctail(), values[nvalues - 1]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1292
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1293
  list.unlink(*values[0]);
48806
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1294
  EXPECT_EQ(NULL_BLOCK, list.next(*values[0]));
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1295
  EXPECT_EQ(NULL_BLOCK, list.prev(*values[0]));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1296
  EXPECT_EQ(list.chead(), values[1]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1297
  EXPECT_EQ(list.ctail(), values[nvalues - 1]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1298
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1299
  const OopBlock* block = list.chead();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1300
  for (size_t i = 1; i < nvalues; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1301
    EXPECT_EQ(block, values[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1302
    block = list.next(*block);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1303
  }
48806
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1304
  EXPECT_EQ(NULL_BLOCK, block);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1305
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1306
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1307
TEST_F(OopStorageBlockListTestWithList, unlink_back) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1308
  EXPECT_EQ(list.chead(), values[0]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1309
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1310
  list.unlink(*values[nvalues - 1]);
48806
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1311
  EXPECT_EQ(NULL_BLOCK, list.next(*values[nvalues - 1]));
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1312
  EXPECT_EQ(NULL_BLOCK, list.prev(*values[nvalues - 1]));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1313
  EXPECT_EQ(list.chead(), values[0]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1314
  EXPECT_EQ(list.ctail(), values[nvalues - 2]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1315
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1316
  const OopBlock* block = list.chead();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1317
  for (size_t i = 0; i < nvalues - 1; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1318
    EXPECT_EQ(block, values[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1319
    block = list.next(*block);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1320
  }
48806
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1321
  EXPECT_EQ(NULL_BLOCK, block);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1322
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1323
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1324
TEST_F(OopStorageBlockListTestWithList, unlink_middle) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1325
  EXPECT_EQ(list.chead(), values[0]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1326
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1327
  size_t index = nvalues / 2;
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1328
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1329
  list.unlink(*values[index]);
48806
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1330
  EXPECT_EQ(NULL_BLOCK, list.next(*values[index]));
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1331
  EXPECT_EQ(NULL_BLOCK, list.prev(*values[index]));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1332
  EXPECT_EQ(list.chead(), values[0]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1333
  EXPECT_EQ(list.ctail(), values[nvalues - 1]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1334
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1335
  const OopBlock* block = list.chead();
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1336
  for (size_t i = 0; i < index; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1337
    EXPECT_EQ(block, values[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1338
    block = list.next(*block);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1339
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1340
  for (size_t i = index + 1; i < nvalues; ++i) {
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1341
    EXPECT_EQ(block, values[i]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1342
    block = list.next(*block);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1343
  }
48806
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1344
  EXPECT_EQ(NULL_BLOCK, block);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1345
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1346
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1347
TEST_F(OopStorageBlockListTest, single) {
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1348
  OopBlockList list(&OopBlock::get_allocate_entry);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1349
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1350
  list.push_back(*values[0]);
48806
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1351
  EXPECT_EQ(NULL_BLOCK, list.next(*values[0]));
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1352
  EXPECT_EQ(NULL_BLOCK, list.prev(*values[0]));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1353
  EXPECT_EQ(list.chead(), values[0]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1354
  EXPECT_EQ(list.ctail(), values[0]);
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1355
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1356
  list.unlink(*values[0]);
48806
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1357
  EXPECT_EQ(NULL_BLOCK, list.next(*values[0]));
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1358
  EXPECT_EQ(NULL_BLOCK, list.prev(*values[0]));
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1359
  EXPECT_EQ(NULL_BLOCK, list.chead());
51fc22e5fb00 8195691: AIX build broken after 8194312
mdoerr
parents: 48787
diff changeset
  1360
  EXPECT_EQ(NULL_BLOCK, list.ctail());
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1361
}
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1362
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1363
class OopStorageBlockArrayTest : public OopStorageBlockCollectionTest {};
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1364
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1365
TEST_F(OopStorageBlockArrayTest, empty_array) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1366
  OopBlockArray* a = OopBlockArray::create(nvalues);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1367
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1368
  EXPECT_EQ(nvalues, a->size());
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1369
  EXPECT_EQ(0u, a->block_count_acquire());
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1370
  TestAccess::block_array_set_block_count(a, 2);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1371
  EXPECT_EQ(2u, a->block_count_acquire());
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1372
  TestAccess::block_array_set_block_count(a, 0);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1373
  a->increment_refcount();
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1374
  a->increment_refcount();
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1375
  EXPECT_FALSE(a->decrement_refcount());
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1376
  EXPECT_TRUE(a->decrement_refcount());
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1377
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1378
  OopBlockArray::destroy(a);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1379
}
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1380
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1381
TEST_F(OopStorageBlockArrayTest, push) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1382
  OopBlockArray* a = OopBlockArray::create(nvalues - 1);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1383
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1384
  for (size_t i = 0; i < nvalues - 1; ++i) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1385
    EXPECT_TRUE(a->push(values[i]));
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1386
    EXPECT_EQ(i + 1, a->block_count_acquire());
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1387
    EXPECT_EQ(values[i], a->at(i));
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1388
  }
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1389
  EXPECT_FALSE(a->push(values[nvalues - 1]));
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1390
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1391
  TestAccess::block_array_set_block_count(a, 0);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1392
  OopBlockArray::destroy(a);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1393
}
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1394
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1395
class OopStorageBlockArrayTestWithArray : public OopStorageBlockArrayTest {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1396
public:
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1397
  OopStorageBlockArrayTestWithArray() : a(OopBlockArray::create(nvalues)) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1398
    for (size_t i = 0; i < nvalues; ++i) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1399
      a->push(values[i]);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1400
    }
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1401
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1402
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1403
  ~OopStorageBlockArrayTestWithArray() {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1404
    TestAccess::block_array_set_block_count(a, 0);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1405
    OopBlockArray::destroy(a);
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1406
  }
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1407
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1408
  OopBlockArray* a;
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1409
};
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1410
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1411
TEST_F(OopStorageBlockArrayTestWithArray, remove0) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1412
  a->remove(values[0]);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1413
  EXPECT_EQ(nvalues - 1, a->block_count_acquire());
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1414
  EXPECT_EQ(values[nvalues - 1], a->at(0));
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1415
  for (size_t i = 1; i < nvalues - 1; ++i) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1416
    EXPECT_EQ(values[i], a->at(i));
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1417
  }
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1418
}
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1419
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1420
TEST_F(OopStorageBlockArrayTestWithArray, remove3) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1421
  a->remove(values[3]);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1422
  EXPECT_EQ(nvalues - 1, a->block_count_acquire());
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1423
  for (size_t i = 0; i < 3; ++i) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1424
    EXPECT_EQ(values[i], a->at(i));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1425
  }
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1426
  EXPECT_EQ(values[nvalues - 1], a->at(3));
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1427
  for (size_t i = 4; i < nvalues - 1; ++i) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1428
    EXPECT_EQ(values[i], a->at(i));
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1429
  }
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1430
}
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1431
49977
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1432
TEST_F(OopStorageBlockArrayTestWithArray, remove_last) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1433
  a->remove(values[nvalues - 1]);
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1434
  EXPECT_EQ(nvalues - 1, a->block_count_acquire());
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1435
  for (size_t i = 0; i < nvalues - 1; ++i) {
9f758f0bb058 8200557: OopStorage parallel iteration scales poorly
kbarrett
parents: 49711
diff changeset
  1436
    EXPECT_EQ(values[i], a->at(i));
48787
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1437
  }
7638bf98a312 8194312: Support parallel and concurrent JNI global handle processing
kbarrett
parents:
diff changeset
  1438
}