src/hotspot/share/gc/shared/weakProcessorPhases.cpp
author avoitylov
Thu, 30 Aug 2018 16:33:14 -0400
changeset 51599 3198179d97fa
parent 51546 b9f6a4427da9
child 53536 482109fae02b
permissions -rw-r--r--
8210164: building Minimal VM fails with error: comparison of unsigned expression < 0 is always false [-Werror=type-limits] Summary: Conditionalize compare with serial_phase_count. Reviewed-by: kbarrett, shade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51546
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
     1
/*
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
     4
 *
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
     8
 *
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    13
 * accompanied this code).
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    14
 *
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    18
 *
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    21
 * questions.
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    22
 *
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    23
 */
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    24
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    25
#include "precompiled.hpp"
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    26
#include "classfile/systemDictionary.hpp"
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    27
#include "gc/shared/weakProcessorPhases.hpp"
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    28
#include "runtime/jniHandles.hpp"
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    29
#include "utilities/debug.hpp"
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    30
#include "utilities/macros.hpp"
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    31
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    32
#if INCLUDE_JFR
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    33
#include "jfr/jfr.hpp"
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    34
#endif // INCLUDE_JFR
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    35
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    36
#if INCLUDE_JVMTI
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    37
#include "prims/jvmtiExport.hpp"
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    38
#endif // INCLUDE_JVMTI
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    39
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    40
WeakProcessorPhases::Phase WeakProcessorPhases::phase(uint value) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    41
  assert(value < phase_count, "Invalid phase value %u", value);
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    42
  return static_cast<Phase>(value);
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    43
}
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    44
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    45
uint WeakProcessorPhases::index(Phase phase) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    46
  uint value = static_cast<uint>(phase);
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    47
  assert(value < phase_count, "Invalid phase %u", value);
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    48
  return value;
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    49
}
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    50
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    51
uint WeakProcessorPhases::serial_index(Phase phase) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    52
  assert(is_serial(phase), "not serial phase %u", index(phase));
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    53
  return index(phase) - serial_phase_start;
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    54
}
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    55
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    56
uint WeakProcessorPhases::oop_storage_index(Phase phase) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    57
  assert(is_oop_storage(phase), "not oop storage phase %u", index(phase));
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    58
  return index(phase) - oop_storage_phase_start;
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    59
}
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    60
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    61
bool WeakProcessorPhases::is_serial(Phase phase) {
51599
3198179d97fa 8210164: building Minimal VM fails with error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
avoitylov
parents: 51546
diff changeset
    62
  // serial_phase_count is 0 if JFR and JVMTI are both not built,
3198179d97fa 8210164: building Minimal VM fails with error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
avoitylov
parents: 51546
diff changeset
    63
  // making this check with unsigned lhs redundant
3198179d97fa 8210164: building Minimal VM fails with error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
avoitylov
parents: 51546
diff changeset
    64
#if INCLUDE_JVMTI || INCLUDE_JFR
51546
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    65
  return (index(phase) - serial_phase_start) < serial_phase_count;
51599
3198179d97fa 8210164: building Minimal VM fails with error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
avoitylov
parents: 51546
diff changeset
    66
#else
3198179d97fa 8210164: building Minimal VM fails with error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
avoitylov
parents: 51546
diff changeset
    67
  STATIC_ASSERT(serial_phase_count == 0);
3198179d97fa 8210164: building Minimal VM fails with error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
avoitylov
parents: 51546
diff changeset
    68
  return false;
3198179d97fa 8210164: building Minimal VM fails with error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
avoitylov
parents: 51546
diff changeset
    69
#endif
51546
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    70
}
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    71
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    72
bool WeakProcessorPhases::is_oop_storage(Phase phase) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    73
  return (index(phase) - oop_storage_phase_start) < oop_storage_phase_count;
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    74
}
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    75
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    76
const char* WeakProcessorPhases::description(Phase phase) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    77
  switch (phase) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    78
  JVMTI_ONLY(case jvmti: return "JVMTI weak processing";)
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    79
  JFR_ONLY(case jfr: return "JFR weak processing";)
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    80
  case jni: return "JNI weak processing";
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    81
  case vm: return "VM weak processing";
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    82
  default:
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    83
    ShouldNotReachHere();
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    84
    return "Invalid weak processing phase";
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    85
  }
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    86
}
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    87
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    88
WeakProcessorPhases::Processor WeakProcessorPhases::processor(Phase phase) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    89
  switch (phase) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    90
  JVMTI_ONLY(case jvmti: return &JvmtiExport::weak_oops_do;)
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    91
  JFR_ONLY(case jfr: return &Jfr::weak_oops_do;)
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    92
  default:
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    93
    ShouldNotReachHere();
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    94
    return NULL;
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    95
  }
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    96
}
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    97
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    98
OopStorage* WeakProcessorPhases::oop_storage(Phase phase) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
    99
  switch (phase) {
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
   100
  case jni: return JNIHandles::weak_global_handles();
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
   101
  case vm: return SystemDictionary::vm_weak_oop_storage();
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
   102
  default:
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
   103
    ShouldNotReachHere();
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
   104
    return NULL;
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
   105
  }
b9f6a4427da9 8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
diff changeset
   106
}