src/share/vm/runtime/jfieldIDWorkaround.hpp

Mon, 12 Aug 2019 18:30:40 +0300

author
apetushkov
date
Mon, 12 Aug 2019 18:30:40 +0300
changeset 9858
b985cbb00e68
parent 4037
da91efe96a93
child 6876
710a3c8b516e
permissions
-rw-r--r--

8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens

duke@435 1 /*
coleenp@4037 2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_RUNTIME_JFIELDIDWORKAROUND_HPP
stefank@2314 26 #define SHARE_VM_RUNTIME_JFIELDIDWORKAROUND_HPP
stefank@2314 27
duke@435 28 class jfieldIDWorkaround: AllStatic {
duke@435 29 // This workaround is because JVMTI doesn't have distinct entry points
duke@435 30 // for methods that use static jfieldIDs and instance jfieldIDs.
duke@435 31 // The workaround is to steal a low-order bit:
duke@435 32 // a 1 means the jfieldID is an instance jfieldID,
duke@435 33 // and the rest of the word is the offset of the field.
duke@435 34 // a 0 means the jfieldID is a static jfieldID,
duke@435 35 // and the rest of the word is the JNIid*.
duke@435 36 //
duke@435 37 // Another low-order bit is used to mark if an instance field
duke@435 38 // is accompanied by an indication of which class it applies to.
duke@435 39 //
duke@435 40 // Bit-format of a jfieldID (most significant first):
duke@435 41 // address:30 instance=0:1 checked=0:1
duke@435 42 // offset:30 instance=1:1 checked=0:1
duke@435 43 // klass:23 offset:7 instance=1:1 checked=1:1
duke@435 44 //
duke@435 45 // If the offset does not fit in 7 bits, or if the fieldID is
duke@435 46 // not checked, then the checked bit is zero and the rest of
duke@435 47 // the word (30 bits) contains only the offset.
duke@435 48 //
duke@435 49 private:
duke@435 50 enum {
duke@435 51 checked_bits = 1,
duke@435 52 instance_bits = 1,
duke@435 53 address_bits = BitsPerWord - checked_bits - instance_bits,
duke@435 54
duke@435 55 large_offset_bits = address_bits, // unioned with address
duke@435 56 small_offset_bits = 7,
duke@435 57 klass_bits = address_bits - small_offset_bits,
duke@435 58
duke@435 59 checked_shift = 0,
duke@435 60 instance_shift = checked_shift + checked_bits,
duke@435 61 address_shift = instance_shift + instance_bits,
duke@435 62
duke@435 63 offset_shift = address_shift, // unioned with address
duke@435 64 klass_shift = offset_shift + small_offset_bits,
duke@435 65
duke@435 66 checked_mask_in_place = right_n_bits(checked_bits) << checked_shift,
duke@435 67 instance_mask_in_place = right_n_bits(instance_bits) << instance_shift,
duke@435 68 #ifndef _WIN64
duke@435 69 large_offset_mask = right_n_bits(large_offset_bits),
duke@435 70 small_offset_mask = right_n_bits(small_offset_bits),
duke@435 71 klass_mask = right_n_bits(klass_bits)
duke@435 72 #endif
duke@435 73 };
duke@435 74
duke@435 75 #ifdef _WIN64
duke@435 76 // These values are too big for Win64
duke@435 77 const static uintptr_t large_offset_mask = right_n_bits(large_offset_bits);
duke@435 78 const static uintptr_t small_offset_mask = right_n_bits(small_offset_bits);
duke@435 79 const static uintptr_t klass_mask = right_n_bits(klass_bits);
duke@435 80 #endif
duke@435 81
duke@435 82 // helper routines:
duke@435 83 static bool is_checked_jfieldID(jfieldID id) {
duke@435 84 uintptr_t as_uint = (uintptr_t) id;
duke@435 85 return ((as_uint & checked_mask_in_place) != 0);
duke@435 86 }
duke@435 87 static intptr_t raw_instance_offset(jfieldID id) {
duke@435 88 uintptr_t result = (uintptr_t) id >> address_shift;
duke@435 89 if (VerifyJNIFields && is_checked_jfieldID(id)) {
duke@435 90 result &= small_offset_mask; // cut off the hash bits
duke@435 91 }
duke@435 92 return (intptr_t)result;
duke@435 93 }
coleenp@4037 94 static intptr_t encode_klass_hash(Klass* k, intptr_t offset);
coleenp@4037 95 static bool klass_hash_ok(Klass* k, jfieldID id);
coleenp@4037 96 static void verify_instance_jfieldID(Klass* k, jfieldID id);
duke@435 97
duke@435 98 public:
coleenp@4037 99 static bool is_valid_jfieldID(Klass* k, jfieldID id);
duke@435 100
coleenp@4037 101 static bool is_instance_jfieldID(Klass* k, jfieldID id) {
duke@435 102 uintptr_t as_uint = (uintptr_t) id;
duke@435 103 return ((as_uint & instance_mask_in_place) != 0);
duke@435 104 }
duke@435 105 static bool is_static_jfieldID(jfieldID id) {
duke@435 106 uintptr_t as_uint = (uintptr_t) id;
duke@435 107 return ((as_uint & instance_mask_in_place) == 0);
duke@435 108 }
duke@435 109
coleenp@4037 110 static jfieldID to_instance_jfieldID(Klass* k, int offset) {
duke@435 111 intptr_t as_uint = ((offset & large_offset_mask) << offset_shift) | instance_mask_in_place;
duke@435 112 if (VerifyJNIFields) {
duke@435 113 as_uint |= encode_klass_hash(k, offset);
duke@435 114 }
duke@435 115 jfieldID result = (jfieldID) as_uint;
duke@435 116 #ifndef ASSERT
duke@435 117 // always verify in debug mode; switchable in anything else
duke@435 118 if (VerifyJNIFields)
duke@435 119 #endif // ASSERT
duke@435 120 {
duke@435 121 verify_instance_jfieldID(k, result);
duke@435 122 }
duke@435 123 assert(raw_instance_offset(result) == (offset & large_offset_mask), "extract right offset");
duke@435 124 return result;
duke@435 125 }
duke@435 126
coleenp@4037 127 static intptr_t from_instance_jfieldID(Klass* k, jfieldID id) {
duke@435 128 #ifndef ASSERT
duke@435 129 // always verify in debug mode; switchable in anything else
duke@435 130 if (VerifyJNIFields)
duke@435 131 #endif // ASSERT
duke@435 132 {
duke@435 133 verify_instance_jfieldID(k, id);
duke@435 134 }
duke@435 135 return raw_instance_offset(id);
duke@435 136 }
duke@435 137
duke@435 138 static jfieldID to_static_jfieldID(JNIid* id) {
duke@435 139 assert(id->is_static_field_id(), "from_JNIid, but not static field id");
duke@435 140 jfieldID result = (jfieldID) id;
duke@435 141 assert(from_static_jfieldID(result) == id, "must produce the same static id");
duke@435 142 return result;
duke@435 143 }
duke@435 144
duke@435 145 static JNIid* from_static_jfieldID(jfieldID id) {
duke@435 146 assert(jfieldIDWorkaround::is_static_jfieldID(id),
duke@435 147 "to_JNIid, but not static jfieldID");
duke@435 148 JNIid* result = (JNIid*) id;
duke@435 149 assert(result->is_static_field_id(), "to_JNIid, but not static field id");
duke@435 150 return result;
duke@435 151 }
duke@435 152
duke@435 153 static jfieldID to_jfieldID(instanceKlassHandle k, int offset, bool is_static) {
duke@435 154 if (is_static) {
duke@435 155 JNIid *id = k->jni_id_for(offset);
duke@435 156 debug_only(id->set_is_static_field_id());
duke@435 157 return jfieldIDWorkaround::to_static_jfieldID(id);
duke@435 158 } else {
duke@435 159 return jfieldIDWorkaround::to_instance_jfieldID(k(), offset);
duke@435 160 }
duke@435 161 }
duke@435 162 };
stefank@2314 163
stefank@2314 164 #endif // SHARE_VM_RUNTIME_JFIELDIDWORKAROUND_HPP

mercurial