< prev index next >

src/hotspot/share/prims/unsafe.cpp

Print this page
rev 57826 : 8237521: Memory Access API fixes for 32-bit
Reviewed-by: mcimadamore, dholmes
   1 /*
   2  * Copyright (c) 2000, 2019, 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  *


 343 } UNSAFE_END
 344 
 345 UNSAFE_LEAF(void, Unsafe_StoreFence(JNIEnv *env, jobject unsafe)) {
 346   OrderAccess::release();
 347 } UNSAFE_END
 348 
 349 UNSAFE_LEAF(void, Unsafe_FullFence(JNIEnv *env, jobject unsafe)) {
 350   OrderAccess::fence();
 351 } UNSAFE_END
 352 
 353 ////// Allocation requests
 354 
 355 UNSAFE_ENTRY(jobject, Unsafe_AllocateInstance(JNIEnv *env, jobject unsafe, jclass cls)) {
 356   ThreadToNativeFromVM ttnfv(thread);
 357   return env->AllocObject(cls);
 358 } UNSAFE_END
 359 
 360 UNSAFE_ENTRY(jlong, Unsafe_AllocateMemory0(JNIEnv *env, jobject unsafe, jlong size)) {
 361   size_t sz = (size_t)size;
 362 
 363   sz = align_up(sz, HeapWordSize);

 364   void* x = os::malloc(sz, mtOther);
 365 
 366   return addr_to_java(x);
 367 } UNSAFE_END
 368 
 369 UNSAFE_ENTRY(jlong, Unsafe_ReallocateMemory0(JNIEnv *env, jobject unsafe, jlong addr, jlong size)) {
 370   void* p = addr_from_java(addr);
 371   size_t sz = (size_t)size;
 372   sz = align_up(sz, HeapWordSize);

 373 
 374   void* x = os::realloc(p, sz, mtOther);
 375 
 376   return addr_to_java(x);
 377 } UNSAFE_END
 378 
 379 UNSAFE_ENTRY(void, Unsafe_FreeMemory0(JNIEnv *env, jobject unsafe, jlong addr)) {
 380   void* p = addr_from_java(addr);
 381 
 382   os::free(p);
 383 } UNSAFE_END
 384 
 385 UNSAFE_ENTRY(void, Unsafe_SetMemory0(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong size, jbyte value)) {
 386   size_t sz = (size_t)size;
 387 
 388   oop base = JNIHandles::resolve(obj);
 389   void* p = index_oop_from_field_offset_long(base, offset);
 390 
 391   Copy::fill_to_memory_atomic(p, sz, value);
 392 } UNSAFE_END


   1 /*
   2  * Copyright (c) 2000, 2020, 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  *


 343 } UNSAFE_END
 344 
 345 UNSAFE_LEAF(void, Unsafe_StoreFence(JNIEnv *env, jobject unsafe)) {
 346   OrderAccess::release();
 347 } UNSAFE_END
 348 
 349 UNSAFE_LEAF(void, Unsafe_FullFence(JNIEnv *env, jobject unsafe)) {
 350   OrderAccess::fence();
 351 } UNSAFE_END
 352 
 353 ////// Allocation requests
 354 
 355 UNSAFE_ENTRY(jobject, Unsafe_AllocateInstance(JNIEnv *env, jobject unsafe, jclass cls)) {
 356   ThreadToNativeFromVM ttnfv(thread);
 357   return env->AllocObject(cls);
 358 } UNSAFE_END
 359 
 360 UNSAFE_ENTRY(jlong, Unsafe_AllocateMemory0(JNIEnv *env, jobject unsafe, jlong size)) {
 361   size_t sz = (size_t)size;
 362 
 363   assert(is_aligned(sz, HeapWordSize), "sz not aligned");
 364 
 365   void* x = os::malloc(sz, mtOther);
 366 
 367   return addr_to_java(x);
 368 } UNSAFE_END
 369 
 370 UNSAFE_ENTRY(jlong, Unsafe_ReallocateMemory0(JNIEnv *env, jobject unsafe, jlong addr, jlong size)) {
 371   void* p = addr_from_java(addr);
 372   size_t sz = (size_t)size;
 373 
 374   assert(is_aligned(sz, HeapWordSize), "sz not aligned");
 375 
 376   void* x = os::realloc(p, sz, mtOther);
 377 
 378   return addr_to_java(x);
 379 } UNSAFE_END
 380 
 381 UNSAFE_ENTRY(void, Unsafe_FreeMemory0(JNIEnv *env, jobject unsafe, jlong addr)) {
 382   void* p = addr_from_java(addr);
 383 
 384   os::free(p);
 385 } UNSAFE_END
 386 
 387 UNSAFE_ENTRY(void, Unsafe_SetMemory0(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong size, jbyte value)) {
 388   size_t sz = (size_t)size;
 389 
 390   oop base = JNIHandles::resolve(obj);
 391   void* p = index_oop_from_field_offset_long(base, offset);
 392 
 393   Copy::fill_to_memory_atomic(p, sz, value);
 394 } UNSAFE_END


< prev index next >