< prev index next >

src/hotspot/share/oops/valueKlass.cpp

Print this page




  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 #include "precompiled.hpp"
  26 #include "gc/shared/barrierSet.hpp"
  27 #include "gc/shared/collectedHeap.inline.hpp"
  28 #include "gc/shared/gcLocker.inline.hpp"
  29 #include "interpreter/interpreter.hpp"
  30 #include "logging/log.hpp"
  31 #include "memory/metadataFactory.hpp"
  32 #include "oops/access.hpp"
  33 #include "oops/compressedOops.inline.hpp"
  34 #include "oops/fieldStreams.hpp"
  35 #include "oops/instanceKlass.hpp"
  36 #include "oops/method.hpp"
  37 #include "oops/oop.inline.hpp"
  38 #include "oops/objArrayKlass.hpp"
  39 #include "oops/valueKlass.hpp"
  40 #include "oops/valueArrayKlass.hpp"
  41 #include "runtime/fieldDescriptor.inline.hpp"
  42 #include "runtime/handles.inline.hpp"
  43 #include "runtime/safepointVerifiers.hpp"
  44 #include "runtime/sharedRuntime.hpp"
  45 #include "runtime/signature.hpp"
  46 #include "runtime/thread.inline.hpp"
  47 #include "utilities/copy.hpp"
  48 
  49 int ValueKlass::first_field_offset() const {
  50 #ifdef ASSERT
  51   int first_offset = INT_MAX;
  52   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
  53     if (fs.offset() < first_offset) first_offset= fs.offset();
  54   }
  55 #endif


 126 
 127 bool ValueKlass::flatten_array() {
 128   if (!ValueArrayFlatten) {
 129     return false;
 130   }
 131 
 132   int elem_bytes = raw_value_byte_size();
 133   // Too big
 134   if ((ValueArrayElemMaxFlatSize >= 0) && (elem_bytes > ValueArrayElemMaxFlatSize)) {
 135     return false;
 136   }
 137   // Too many embedded oops
 138   if ((ValueArrayElemMaxFlatOops >= 0) && (nonstatic_oop_count() > ValueArrayElemMaxFlatOops)) {
 139     return false;
 140   }
 141 
 142   return true;
 143 }
 144 
 145 
 146 Klass* ValueKlass::array_klass_impl(bool or_null, int n, TRAPS) {
 147   if (!flatten_array()) {
 148     return InstanceKlass::array_klass_impl(or_null, n, THREAD);


 149   }

 150 
 151   // Basically the same as instanceKlass, but using "ValueArrayKlass::allocate_klass"
 152   if (array_klasses() == NULL) {
 153     if (or_null) return NULL;
 154 




 155     ResourceMark rm;
 156     JavaThread *jt = (JavaThread *)THREAD;
 157     {
 158       // Atomic creation of array_klasses
 159       MutexLocker ma(MultiArray_lock, THREAD);
 160 
 161       // Check if update has already taken place
 162       if (array_klasses() == NULL) {
 163         Klass* ak;
 164         if (is_atomic() || (!ValueArrayAtomicAccess)) {
 165           ak = ValueArrayKlass::allocate_klass(this, CHECK_NULL);
 166         } else {
 167           ak = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this, CHECK_NULL);
 168         }
 169         set_array_klasses(ak);
 170       }
 171     }



 172   }
 173   // _this will always be set at this point
 174   ArrayKlass* ak = ArrayKlass::cast(array_klasses());
 175   if (or_null) {
 176     return ak->array_klass_or_null(n);







 177   }
 178   return ak->array_klass(n, THREAD);
 179 }
 180 
 181 Klass* ValueKlass::array_klass_impl(bool or_null, TRAPS) {
 182   return array_klass_impl(or_null, 1, THREAD);


 183 }
 184 
 185 void ValueKlass::raw_field_copy(void* src, void* dst, size_t raw_byte_size) {
 186   /*
 187    * Try not to shear fields even if not an atomic store...
 188    *
 189    * First 3 cases handle value array store, otherwise works on the same basis
 190    * as JVM_Clone, at this size data is aligned. The order of primitive types
 191    * is largest to smallest, and it not possible for fields to stradle long
 192    * copy boundaries.
 193    *
 194    * If MT without exclusive access, possible to observe partial value store,
 195    * but not partial primitive and reference field values
 196    */
 197   switch (raw_byte_size) {
 198     case 1:
 199       *((jbyte*) dst) = *(jbyte*)src;
 200       break;
 201     case 2:
 202       *((jshort*) dst) = *(jshort*)src;




  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 #include "precompiled.hpp"
  26 #include "gc/shared/barrierSet.hpp"
  27 #include "gc/shared/collectedHeap.inline.hpp"
  28 #include "gc/shared/gcLocker.inline.hpp"
  29 #include "interpreter/interpreter.hpp"
  30 #include "logging/log.hpp"
  31 #include "memory/metadataFactory.hpp"
  32 #include "oops/access.hpp"
  33 #include "oops/compressedOops.inline.hpp"
  34 #include "oops/fieldStreams.hpp"
  35 #include "oops/instanceKlass.inline.hpp"
  36 #include "oops/method.hpp"
  37 #include "oops/oop.inline.hpp"
  38 #include "oops/objArrayKlass.hpp"
  39 #include "oops/valueKlass.hpp"
  40 #include "oops/valueArrayKlass.hpp"
  41 #include "runtime/fieldDescriptor.inline.hpp"
  42 #include "runtime/handles.inline.hpp"
  43 #include "runtime/safepointVerifiers.hpp"
  44 #include "runtime/sharedRuntime.hpp"
  45 #include "runtime/signature.hpp"
  46 #include "runtime/thread.inline.hpp"
  47 #include "utilities/copy.hpp"
  48 
  49 int ValueKlass::first_field_offset() const {
  50 #ifdef ASSERT
  51   int first_offset = INT_MAX;
  52   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
  53     if (fs.offset() < first_offset) first_offset= fs.offset();
  54   }
  55 #endif


 126 
 127 bool ValueKlass::flatten_array() {
 128   if (!ValueArrayFlatten) {
 129     return false;
 130   }
 131 
 132   int elem_bytes = raw_value_byte_size();
 133   // Too big
 134   if ((ValueArrayElemMaxFlatSize >= 0) && (elem_bytes > ValueArrayElemMaxFlatSize)) {
 135     return false;
 136   }
 137   // Too many embedded oops
 138   if ((ValueArrayElemMaxFlatOops >= 0) && (nonstatic_oop_count() > ValueArrayElemMaxFlatOops)) {
 139     return false;
 140   }
 141 
 142   return true;
 143 }
 144 
 145 
 146 Klass* ValueKlass::array_klass_impl(ArrayStorageProperties storage_props, bool or_null, int n, TRAPS) {
 147   if (storage_props.is_flattened()) {
 148     return value_array_klass(storage_props, or_null, n, THREAD);
 149   } else {
 150     return InstanceKlass::array_klass_impl(storage_props, or_null, n, THREAD);
 151   }
 152 }
 153 
 154 Klass* ValueKlass::array_klass_impl(ArrayStorageProperties storage_props, bool or_null, TRAPS) {
 155   return array_klass_impl(storage_props, or_null, 1, THREAD);
 156 }
 157 
 158 Klass* ValueKlass::value_array_klass(ArrayStorageProperties storage_props, bool or_null, int rank, TRAPS) {
 159   Klass* vak = acquire_value_array_klass();
 160   if (vak == NULL) {
 161     if (or_null) return NULL;
 162     ResourceMark rm;
 163     JavaThread *jt = (JavaThread *)THREAD;
 164     {
 165       // Atomic creation of array_klasses
 166       MutexLocker ma(MultiArray_lock, THREAD);
 167       if (get_value_array_klass() == NULL) {
 168         vak = allocate_value_array_klass(CHECK_NULL);
 169         OrderAccess::release_store((Klass**)adr_value_array_klass(), vak);





 170       }

 171     }
 172   }
 173 
 174   if (!vak->is_valueArray_klass()) {
 175     storage_props.clear_flattened();
 176   }


 177   if (or_null) {
 178     return vak->array_klass_or_null(storage_props, rank);
 179   }
 180   return vak->array_klass(storage_props, rank, THREAD);
 181 }
 182 
 183 Klass* ValueKlass::allocate_value_array_klass(TRAPS) {
 184   if (flatten_array() && (is_atomic() || (!ValueArrayAtomicAccess))) {
 185     return ValueArrayKlass::allocate_klass(ArrayStorageProperties::flattened_and_null_free, this, THREAD);
 186   }
 187   return ObjArrayKlass::allocate_objArray_klass(ArrayStorageProperties::null_free, 1, this, THREAD);
 188 }
 189 
 190 void ValueKlass::array_klasses_do(void f(Klass* k)) {
 191   InstanceKlass::array_klasses_do(f);
 192   if (get_value_array_klass() != NULL)
 193     ArrayKlass::cast(get_value_array_klass())->array_klasses_do(f);
 194 }
 195 
 196 void ValueKlass::raw_field_copy(void* src, void* dst, size_t raw_byte_size) {
 197   /*
 198    * Try not to shear fields even if not an atomic store...
 199    *
 200    * First 3 cases handle value array store, otherwise works on the same basis
 201    * as JVM_Clone, at this size data is aligned. The order of primitive types
 202    * is largest to smallest, and it not possible for fields to stradle long
 203    * copy boundaries.
 204    *
 205    * If MT without exclusive access, possible to observe partial value store,
 206    * but not partial primitive and reference field values
 207    */
 208   switch (raw_byte_size) {
 209     case 1:
 210       *((jbyte*) dst) = *(jbyte*)src;
 211       break;
 212     case 2:
 213       *((jshort*) dst) = *(jshort*)src;


< prev index next >