src/share/vm/runtime/jfieldIDWorkaround.hpp

Print this page


   1 /*
   2  * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 



  25 class jfieldIDWorkaround: AllStatic {
  26   // This workaround is because JVMTI doesn't have distinct entry points
  27   // for methods that use static jfieldIDs and instance jfieldIDs.
  28   // The workaround is to steal a low-order bit:
  29   //   a 1 means the jfieldID is an instance jfieldID,
  30   //             and the rest of the word is the offset of the field.
  31   //   a 0 means the jfieldID is a static jfieldID,
  32   //             and the rest of the word is the JNIid*.
  33   //
  34   // Another low-order bit is used to mark if an instance field
  35   // is accompanied by an indication of which class it applies to.
  36   //
  37   // Bit-format of a jfieldID (most significant first):
  38   //  address:30        instance=0:1 checked=0:1
  39   //  offset:30         instance=1:1 checked=0:1
  40   //  klass:23 offset:7 instance=1:1 checked=1:1
  41   //
  42   // If the offset does not fit in 7 bits, or if the fieldID is
  43   // not checked, then the checked bit is zero and the rest of
  44   // the word (30 bits) contains only the offset.


 140   }
 141 
 142   static JNIid* from_static_jfieldID(jfieldID id) {
 143     assert(jfieldIDWorkaround::is_static_jfieldID(id),
 144            "to_JNIid, but not static jfieldID");
 145     JNIid* result = (JNIid*) id;
 146     assert(result->is_static_field_id(), "to_JNIid, but not static field id");
 147     return result;
 148   }
 149 
 150   static jfieldID to_jfieldID(instanceKlassHandle k, int offset, bool is_static) {
 151     if (is_static) {
 152       JNIid *id = k->jni_id_for(offset);
 153       debug_only(id->set_is_static_field_id());
 154       return jfieldIDWorkaround::to_static_jfieldID(id);
 155     } else {
 156       return jfieldIDWorkaround::to_instance_jfieldID(k(), offset);
 157     }
 158   }
 159 };


   1 /*
   2  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_RUNTIME_JFIELDIDWORKAROUND_HPP
  26 #define SHARE_VM_RUNTIME_JFIELDIDWORKAROUND_HPP
  27 
  28 class jfieldIDWorkaround: AllStatic {
  29   // This workaround is because JVMTI doesn't have distinct entry points
  30   // for methods that use static jfieldIDs and instance jfieldIDs.
  31   // The workaround is to steal a low-order bit:
  32   //   a 1 means the jfieldID is an instance jfieldID,
  33   //             and the rest of the word is the offset of the field.
  34   //   a 0 means the jfieldID is a static jfieldID,
  35   //             and the rest of the word is the JNIid*.
  36   //
  37   // Another low-order bit is used to mark if an instance field
  38   // is accompanied by an indication of which class it applies to.
  39   //
  40   // Bit-format of a jfieldID (most significant first):
  41   //  address:30        instance=0:1 checked=0:1
  42   //  offset:30         instance=1:1 checked=0:1
  43   //  klass:23 offset:7 instance=1:1 checked=1:1
  44   //
  45   // If the offset does not fit in 7 bits, or if the fieldID is
  46   // not checked, then the checked bit is zero and the rest of
  47   // the word (30 bits) contains only the offset.


 143   }
 144 
 145   static JNIid* from_static_jfieldID(jfieldID id) {
 146     assert(jfieldIDWorkaround::is_static_jfieldID(id),
 147            "to_JNIid, but not static jfieldID");
 148     JNIid* result = (JNIid*) id;
 149     assert(result->is_static_field_id(), "to_JNIid, but not static field id");
 150     return result;
 151   }
 152 
 153   static jfieldID to_jfieldID(instanceKlassHandle k, int offset, bool is_static) {
 154     if (is_static) {
 155       JNIid *id = k->jni_id_for(offset);
 156       debug_only(id->set_is_static_field_id());
 157       return jfieldIDWorkaround::to_static_jfieldID(id);
 158     } else {
 159       return jfieldIDWorkaround::to_instance_jfieldID(k(), offset);
 160     }
 161   }
 162 };
 163 
 164 #endif // SHARE_VM_RUNTIME_JFIELDIDWORKAROUND_HPP