hotspot/src/share/vm/prims/unsafe.cpp
author dcubed
Thu, 07 Apr 2016 09:47:48 -0700
changeset 37267 ad8c0e8de29f
parent 36827 53d2d43551d2
parent 37248 11a660dbbb8e
child 37480 291ee208fb72
child 38014 8731fa11f766
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
36086
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
     2
 * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5089
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5089
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5089
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 33612
diff changeset
    26
#include "classfile/classFileStream.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "classfile/vmSymbols.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/allocation.inline.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 37184
diff changeset
    29
#include "memory/resourceArea.hpp"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 28621
diff changeset
    30
#include "oops/objArrayOop.inline.hpp"
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 28621
diff changeset
    31
#include "oops/oop.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "prims/jni.h"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "prims/jvm.h"
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
    34
#include "prims/unsafe.hpp"
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 25057
diff changeset
    35
#include "runtime/atomic.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "runtime/globals.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
#include "runtime/interfaceSupport.hpp"
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 24322
diff changeset
    38
#include "runtime/orderAccess.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    39
#include "runtime/reflection.hpp"
25715
d5a8dbdc5150 8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents: 25354
diff changeset
    40
#include "runtime/vm_version.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    41
#include "services/threadService.hpp"
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17881
diff changeset
    42
#include "trace/tracing.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    43
#include "utilities/copy.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    44
#include "utilities/dtrace.hpp"
27684
e0391b2bf625 8064581: Move INCLUDE_ALL_GCS include section to the end of the include list
stefank
parents: 25715
diff changeset
    45
#include "utilities/macros.hpp"
e0391b2bf625 8064581: Move INCLUDE_ALL_GCS include section to the end of the include list
stefank
parents: 25715
diff changeset
    46
#if INCLUDE_ALL_GCS
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30288
diff changeset
    47
#include "gc/g1/g1SATBCardTableModRefBS.hpp"
27684
e0391b2bf625 8064581: Move INCLUDE_ALL_GCS include section to the end of the include list
stefank
parents: 25715
diff changeset
    48
#endif // INCLUDE_ALL_GCS
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    49
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
    50
/**
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
    51
 * Implementation of the jdk.internal.misc.Unsafe class
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
5089
0cce506a0158 6935224: Adding new DTrace probes to work with Palantir
fparain
parents: 3262
diff changeset
    54
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
#define MAX_OBJECT_SIZE \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  ( arrayOopDesc::header_size(T_DOUBLE) * HeapWordSize \
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    + ((julong)max_jint * sizeof(double)) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
#define UNSAFE_ENTRY(result_type, header) \
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
    61
  JVM_ENTRY(static result_type, header)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
    63
#define UNSAFE_LEAF(result_type, header) \
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
    64
  JVM_LEAF(static result_type, header)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
#define UNSAFE_END JVM_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
    69
static inline void* addr_from_java(jlong addr) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // This assert fails in a variety of ways on 32-bit systems.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // It is impossible to predict whether native code that converts
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // pointers to longs will sign-extend or zero-extend the addresses.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  //assert(addr == (uintptr_t)addr, "must not be odd high bits");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  return (void*)(uintptr_t)addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
    77
static inline jlong addr_to_java(void* p) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  assert(p == (void*)(uintptr_t)p, "must not be odd high bits");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  return (uintptr_t)p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
// Note: The VM's obj_field and related accessors use byte-scaled
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
// ("unscaled") offsets, just as the unsafe methods do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
// However, the method Unsafe.fieldOffset explicitly declines to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
// guarantee this.  The field offset values manipulated by the Java user
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
// through the Unsafe API are opaque cookies that just happen to be byte
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
// offsets.  We represent this state of affairs by passing the cookies
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
// through conversion functions when going between the VM and the Unsafe API.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
// The conversion functions just happen to be no-ops at present.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
    93
static inline jlong field_offset_to_byte_offset(jlong field_offset) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  return field_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
    97
static inline jlong field_offset_from_byte_offset(jlong byte_offset) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  return byte_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   101
static inline void* index_oop_from_field_offset_long(oop p, jlong field_offset) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   102
  jlong byte_offset = field_offset_to_byte_offset(field_offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  if (p != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    assert(byte_offset >= 0 && byte_offset <= (jlong)MAX_OBJECT_SIZE, "sane offset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    if (byte_offset == (jint)byte_offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      void* ptr_plus_disp = (address)p + byte_offset;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   109
      assert((void*)p->obj_field_addr<oop>((jint)byte_offset) == ptr_plus_disp,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
             "raw [ptr+disp] must be consistent with oop::field_base");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    }
14127
16ba0a8dfde2 8001071: Add simple range check into VM implemenation of Unsafe access methods
kvn
parents: 13952
diff changeset
   112
    jlong p_size = HeapWordSize * (jlong)(p->size());
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31592
diff changeset
   113
    assert(byte_offset < p_size, "Unsafe access: offset " INT64_FORMAT " > object's size " INT64_FORMAT, byte_offset, p_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
#endif
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   116
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   117
  if (sizeof(char*) == sizeof(jint)) {   // (this constant folds!)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    return (address)p + (jint) byte_offset;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   119
  } else {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    return (address)p +        byte_offset;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   121
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
// Externally callable versions:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
// (Use these in compiler intrinsics which emulate unsafe primitives.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
jlong Unsafe_field_offset_to_byte_offset(jlong field_offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  return field_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
jlong Unsafe_field_offset_from_byte_offset(jlong byte_offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  return byte_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
///// Data in the Java heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
#define GET_FIELD(obj, offset, type_name, v) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  oop p = JNIHandles::resolve(obj); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  type_name v = *(type_name*)index_oop_from_field_offset_long(p, offset)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
#define SET_FIELD(obj, offset, type_name, x) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  oop p = JNIHandles::resolve(obj); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  *(type_name*)index_oop_from_field_offset_long(p, offset) = x
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
#define GET_FIELD_VOLATILE(obj, offset, type_name, v) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  oop p = JNIHandles::resolve(obj); \
22868
7f6eb436873b 8029101: PPC64 (part 211): ordering of Independent Reads of Independent Writes
goetz
parents: 20282
diff changeset
   146
  if (support_IRIW_for_not_multiple_copy_atomic_cpu) { \
7f6eb436873b 8029101: PPC64 (part 211): ordering of Independent Reads of Independent Writes
goetz
parents: 20282
diff changeset
   147
    OrderAccess::fence(); \
7f6eb436873b 8029101: PPC64 (part 211): ordering of Independent Reads of Independent Writes
goetz
parents: 20282
diff changeset
   148
  } \
7885
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   149
  volatile type_name v = OrderAccess::load_acquire((volatile type_name*)index_oop_from_field_offset_long(p, offset));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
#define SET_FIELD_VOLATILE(obj, offset, type_name, x) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  oop p = JNIHandles::resolve(obj); \
7885
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   153
  OrderAccess::release_store_fence((volatile type_name*)index_oop_from_field_offset_long(p, offset), x);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   155
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
// Get/SetObject must be special-cased, since it works with handles.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
25057
f38210f84f8c 8031819: Remove legacy jdk checks and code
hseigel
parents: 24487
diff changeset
   158
// These functions allow a null base pointer with an arbitrary address.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
// But if the base pointer is non-null, the offset should make some sense.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
// That is, it should be in the range [0, MAX_OBJECT_SIZE].
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   161
UNSAFE_ENTRY(jobject, Unsafe_GetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) {
30288
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
   162
  oop p = JNIHandles::resolve(obj);
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
   163
  oop v;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   164
30288
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
   165
  if (UseCompressedOops) {
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
   166
    narrowOop n = *(narrowOop*)index_oop_from_field_offset_long(p, offset);
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
   167
    v = oopDesc::decode_heap_oop(n);
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
   168
  } else {
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
   169
    v = *(oop*)index_oop_from_field_offset_long(p, offset);
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
   170
  }
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   171
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   172
  jobject ret = JNIHandles::make_local(env, v);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   173
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14832
diff changeset
   174
#if INCLUDE_ALL_GCS
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   175
  // We could be accessing the referent field in a reference
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   176
  // object. If G1 is enabled then we need to register non-null
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   177
  // referent with the SATB barrier.
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   178
  if (UseG1GC) {
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   179
    bool needs_barrier = false;
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   180
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   181
    if (ret != NULL) {
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   182
      if (offset == java_lang_ref_Reference::referent_offset && obj != NULL) {
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   183
        oop o = JNIHandles::resolve(obj);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   184
        Klass* k = o->klass();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   185
        if (InstanceKlass::cast(k)->reference_type() != REF_NONE) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   186
          assert(InstanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity");
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   187
          needs_barrier = true;
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   188
        }
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   189
      }
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   190
    }
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   191
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   192
    if (needs_barrier) {
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   193
      oop referent = JNIHandles::resolve(ret);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   194
      G1SATBCardTableModRefBS::enqueue(referent);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   195
    }
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8725
diff changeset
   196
  }
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14832
diff changeset
   197
#endif // INCLUDE_ALL_GCS
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   199
  return ret;
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   200
} UNSAFE_END
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   201
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   202
UNSAFE_ENTRY(void, Unsafe_SetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  oop x = JNIHandles::resolve(x_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  oop p = JNIHandles::resolve(obj);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   205
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   206
  if (UseCompressedOops) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   207
    oop_store((narrowOop*)index_oop_from_field_offset_long(p, offset), x);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   208
  } else {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   209
    oop_store((oop*)index_oop_from_field_offset_long(p, offset), x);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   210
  }
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   211
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   213
UNSAFE_ENTRY(jobject, Unsafe_GetObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) {
13293
c2b4f191c489 7087357: JSR 292: remove obsolete code after 7085860
twisti
parents: 10967
diff changeset
   214
  oop p = JNIHandles::resolve(obj);
c2b4f191c489 7087357: JSR 292: remove obsolete code after 7085860
twisti
parents: 10967
diff changeset
   215
  void* addr = index_oop_from_field_offset_long(p, offset);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   216
13293
c2b4f191c489 7087357: JSR 292: remove obsolete code after 7085860
twisti
parents: 10967
diff changeset
   217
  volatile oop v;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   218
13293
c2b4f191c489 7087357: JSR 292: remove obsolete code after 7085860
twisti
parents: 10967
diff changeset
   219
  if (UseCompressedOops) {
c2b4f191c489 7087357: JSR 292: remove obsolete code after 7085860
twisti
parents: 10967
diff changeset
   220
    volatile narrowOop n = *(volatile narrowOop*) addr;
20282
7f9cbdf89af2 7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents: 18025
diff changeset
   221
    (void)const_cast<oop&>(v = oopDesc::decode_heap_oop(n));
13293
c2b4f191c489 7087357: JSR 292: remove obsolete code after 7085860
twisti
parents: 10967
diff changeset
   222
  } else {
20282
7f9cbdf89af2 7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents: 18025
diff changeset
   223
    (void)const_cast<oop&>(v = *(volatile oop*) addr);
13293
c2b4f191c489 7087357: JSR 292: remove obsolete code after 7085860
twisti
parents: 10967
diff changeset
   224
  }
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   225
13293
c2b4f191c489 7087357: JSR 292: remove obsolete code after 7085860
twisti
parents: 10967
diff changeset
   226
  OrderAccess::acquire();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  return JNIHandles::make_local(env, v);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   228
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   230
UNSAFE_ENTRY(void, Unsafe_SetObjectVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject x_h)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  oop x = JNIHandles::resolve(x_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  oop p = JNIHandles::resolve(obj);
7885
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   233
  void* addr = index_oop_from_field_offset_long(p, offset);
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   234
  OrderAccess::release();
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   235
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   236
  if (UseCompressedOops) {
7885
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   237
    oop_store((narrowOop*)addr, x);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   238
  } else {
7885
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   239
    oop_store((oop*)addr, x);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   240
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   242
  OrderAccess::fence();
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   243
} UNSAFE_END
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   244
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   245
UNSAFE_ENTRY(jobject, Unsafe_GetUncompressedObject(JNIEnv *env, jobject unsafe, jlong addr)) {
30288
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
   246
  oop v = *(oop*) (address) addr;
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
   247
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   248
  return JNIHandles::make_local(env, v);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   249
} UNSAFE_END
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   250
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   251
UNSAFE_ENTRY(jclass, Unsafe_GetJavaMirror(JNIEnv *env, jobject unsafe, jlong metaspace_klass)) {
30288
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
   252
  Klass* klass = (Klass*) (address) metaspace_klass;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   253
30288
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
   254
  return (jclass) JNIHandles::make_local(klass->java_mirror());
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   255
} UNSAFE_END
30288
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
   256
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   257
UNSAFE_ENTRY(jlong, Unsafe_GetKlassPointer(JNIEnv *env, jobject unsafe, jobject obj)) {
30288
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
   258
  oop o = JNIHandles::resolve(obj);
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
   259
  jlong klass = (jlong) (address) o->klass();
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   260
30288
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
   261
  return klass;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   262
} UNSAFE_END
30288
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
   263
17316
c1f00a6ecf59 8013633: Cleanup platform ifdefs in unsafe.cpp
bpittore
parents: 16617
diff changeset
   264
#ifndef SUPPORTS_NATIVE_CX8
7885
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   265
27874
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   266
// VM_Version::supports_cx8() is a surrogate for 'supports atomic long memory ops'.
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   267
//
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   268
// On platforms which do not support atomic compare-and-swap of jlong (8 byte)
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   269
// values we have to use a lock-based scheme to enforce atomicity. This has to be
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   270
// applied to all Unsafe operations that set the value of a jlong field. Even so
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   271
// the compareAndSwapLong operation will not be atomic with respect to direct stores
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   272
// to the field from Java code. It is important therefore that any Java code that
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   273
// utilizes these Unsafe jlong operations does not perform direct stores. To permit
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   274
// direct loads of the field from Java code we must also use Atomic::store within the
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   275
// locked regions. And for good measure, in case there are direct stores, we also
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   276
// employ Atomic::load within those regions. Note that the field in question must be
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   277
// volatile and so must have atomic load/store accesses applied at the Java level.
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   278
//
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   279
// The locking scheme could utilize a range of strategies for controlling the locking
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   280
// granularity: from a lock per-field through to a single global lock. The latter is
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   281
// the simplest and is used for the current implementation. Note that the Java object
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   282
// that contains the field, can not, in general, be used for locking. To do so can lead
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   283
// to deadlocks as we may introduce locking into what appears to the Java code to be a
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   284
// lock-free path.
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   285
//
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   286
// As all the locked-regions are very short and themselves non-blocking we can treat
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   287
// them as leaf routines and elide safepoint checks (ie we don't perform any thread
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   288
// state transitions even when blocking for the lock). Note that if we do choose to
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   289
// add safepoint checks and thread state transitions, we must ensure that we calculate
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   290
// the address of the field _after_ we have acquired the lock, else the object may have
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
   291
// been moved by the GC
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   293
UNSAFE_ENTRY(jlong, Unsafe_GetLongVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   294
  if (VM_Version::supports_cx8()) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   295
    GET_FIELD_VOLATILE(obj, offset, jlong, v);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   296
    return v;
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   297
  } else {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   298
    Handle p (THREAD, JNIHandles::resolve(obj));
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   299
    jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset));
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   300
    MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   301
    jlong value = Atomic::load(addr);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   302
    return value;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  }
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   304
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   306
UNSAFE_ENTRY(void, Unsafe_SetLongVolatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong x)) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   307
  if (VM_Version::supports_cx8()) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   308
    SET_FIELD_VOLATILE(obj, offset, jlong, x);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   309
  } else {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   310
    Handle p (THREAD, JNIHandles::resolve(obj));
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   311
    jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset));
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   312
    MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   313
    Atomic::store(x, addr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  }
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   315
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
17316
c1f00a6ecf59 8013633: Cleanup platform ifdefs in unsafe.cpp
bpittore
parents: 16617
diff changeset
   317
#endif // not SUPPORTS_NATIVE_CX8
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   319
UNSAFE_LEAF(jboolean, Unsafe_isBigEndian0(JNIEnv *env, jobject unsafe)) {
30209
8ea30dc99369 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 29083
diff changeset
   320
#ifdef VM_LITTLE_ENDIAN
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   321
  return false;
30209
8ea30dc99369 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 29083
diff changeset
   322
#else
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   323
  return true;
30209
8ea30dc99369 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 29083
diff changeset
   324
#endif
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   325
} UNSAFE_END
30209
8ea30dc99369 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 29083
diff changeset
   326
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   327
UNSAFE_LEAF(jint, Unsafe_unalignedAccess0(JNIEnv *env, jobject unsafe)) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   328
  return UseUnalignedAccesses;
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   329
} UNSAFE_END
30209
8ea30dc99369 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 29083
diff changeset
   330
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   331
#define DEFINE_GETSETOOP(java_type, Type)        \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
 \
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   333
UNSAFE_ENTRY(java_type, Unsafe_Get##Type(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) { \
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   334
  GET_FIELD(obj, offset, java_type, v); \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  return v; \
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   336
} UNSAFE_END \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
 \
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   338
UNSAFE_ENTRY(void, Unsafe_Set##Type(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, java_type x)) { \
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   339
  SET_FIELD(obj, offset, java_type, x); \
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   340
} UNSAFE_END \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
// END DEFINE_GETSETOOP.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
7885
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   344
DEFINE_GETSETOOP(jboolean, Boolean)
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   345
DEFINE_GETSETOOP(jbyte, Byte)
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   346
DEFINE_GETSETOOP(jshort, Short);
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   347
DEFINE_GETSETOOP(jchar, Char);
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   348
DEFINE_GETSETOOP(jint, Int);
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   349
DEFINE_GETSETOOP(jlong, Long);
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   350
DEFINE_GETSETOOP(jfloat, Float);
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   351
DEFINE_GETSETOOP(jdouble, Double);
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   352
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   353
#undef DEFINE_GETSETOOP
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   355
#define DEFINE_GETSETOOP_VOLATILE(java_type, Type) \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
 \
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   357
UNSAFE_ENTRY(java_type, Unsafe_Get##Type##Volatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) { \
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   358
  GET_FIELD_VOLATILE(obj, offset, java_type, v); \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  return v; \
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   360
} UNSAFE_END \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
 \
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   362
UNSAFE_ENTRY(void, Unsafe_Set##Type##Volatile(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, java_type x)) { \
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   363
  SET_FIELD_VOLATILE(obj, offset, java_type, x); \
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   364
} UNSAFE_END \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
// END DEFINE_GETSETOOP_VOLATILE.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
DEFINE_GETSETOOP_VOLATILE(jboolean, Boolean)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
DEFINE_GETSETOOP_VOLATILE(jbyte, Byte)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
DEFINE_GETSETOOP_VOLATILE(jshort, Short);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
DEFINE_GETSETOOP_VOLATILE(jchar, Char);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
DEFINE_GETSETOOP_VOLATILE(jint, Int);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
DEFINE_GETSETOOP_VOLATILE(jfloat, Float);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
DEFINE_GETSETOOP_VOLATILE(jdouble, Double);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
17316
c1f00a6ecf59 8013633: Cleanup platform ifdefs in unsafe.cpp
bpittore
parents: 16617
diff changeset
   376
#ifdef SUPPORTS_NATIVE_CX8
7885
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   377
DEFINE_GETSETOOP_VOLATILE(jlong, Long);
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   378
#endif
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   379
c02b05ba16a1 7009756: volatile variables could be broken throw reflection API
kvn
parents: 7397
diff changeset
   380
#undef DEFINE_GETSETOOP_VOLATILE
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   382
UNSAFE_LEAF(void, Unsafe_LoadFence(JNIEnv *env, jobject unsafe)) {
14832
61b025224ac9 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 14588
diff changeset
   383
  OrderAccess::acquire();
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   384
} UNSAFE_END
14832
61b025224ac9 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 14588
diff changeset
   385
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   386
UNSAFE_LEAF(void, Unsafe_StoreFence(JNIEnv *env, jobject unsafe)) {
14832
61b025224ac9 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 14588
diff changeset
   387
  OrderAccess::release();
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   388
} UNSAFE_END
14832
61b025224ac9 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 14588
diff changeset
   389
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   390
UNSAFE_LEAF(void, Unsafe_FullFence(JNIEnv *env, jobject unsafe)) {
14832
61b025224ac9 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 14588
diff changeset
   391
  OrderAccess::fence();
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   392
} UNSAFE_END
14832
61b025224ac9 8004318: JEP-171: Support Unsafe fences intrinsics
kvn
parents: 14588
diff changeset
   393
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
////// Data in the C heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
// Note:  These do not throw NullPointerException for bad pointers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
// They just crash.  Only a oop base pointer can generate a NullPointerException.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
#define DEFINE_GETSETNATIVE(java_type, Type, native_type) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
 \
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   401
UNSAFE_ENTRY(java_type, Unsafe_GetNative##Type(JNIEnv *env, jobject unsafe, jlong addr)) { \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  void* p = addr_from_java(addr); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  JavaThread* t = JavaThread::current(); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  t->set_doing_unsafe_access(true); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  java_type x = *(volatile native_type*)p; \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  t->set_doing_unsafe_access(false); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  return x; \
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   408
} UNSAFE_END \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
 \
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   410
UNSAFE_ENTRY(void, Unsafe_SetNative##Type(JNIEnv *env, jobject unsafe, jlong addr, java_type x)) { \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  JavaThread* t = JavaThread::current(); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  t->set_doing_unsafe_access(true); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  void* p = addr_from_java(addr); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  *(volatile native_type*)p = x; \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  t->set_doing_unsafe_access(false); \
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   416
} UNSAFE_END \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
// END DEFINE_GETSETNATIVE.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
DEFINE_GETSETNATIVE(jbyte, Byte, signed char)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
DEFINE_GETSETNATIVE(jshort, Short, signed short);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
DEFINE_GETSETNATIVE(jchar, Char, unsigned short);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
DEFINE_GETSETNATIVE(jint, Int, jint);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
// no long -- handled specially
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
DEFINE_GETSETNATIVE(jfloat, Float, float);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
DEFINE_GETSETNATIVE(jdouble, Double, double);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
#undef DEFINE_GETSETNATIVE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   430
UNSAFE_ENTRY(jlong, Unsafe_GetNativeLong(JNIEnv *env, jobject unsafe, jlong addr)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  JavaThread* t = JavaThread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  // We do it this way to avoid problems with access to heap using 64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  // bit loads, as jlong in heap could be not 64-bit aligned, and on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  // some CPUs (SPARC) it leads to SIGBUS.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  t->set_doing_unsafe_access(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  void* p = addr_from_java(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  jlong x;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   438
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   439
  if (is_ptr_aligned(p, sizeof(jlong)) == 0) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    // jlong is aligned, do a volatile access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    x = *(volatile jlong*)p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    jlong_accessor acc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    acc.words[0] = ((volatile jint*)p)[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    acc.words[1] = ((volatile jint*)p)[1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    x = acc.long_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  }
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   448
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  t->set_doing_unsafe_access(false);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   450
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  return x;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   452
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   454
UNSAFE_ENTRY(void, Unsafe_SetNativeLong(JNIEnv *env, jobject unsafe, jlong addr, jlong x)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  JavaThread* t = JavaThread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  // see comment for Unsafe_GetNativeLong
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  t->set_doing_unsafe_access(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  void* p = addr_from_java(addr);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   459
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   460
  if (is_ptr_aligned(p, sizeof(jlong))) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
    // jlong is aligned, do a volatile access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
    *(volatile jlong*)p = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    jlong_accessor acc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    acc.long_value = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
    ((volatile jint*)p)[0] = acc.words[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    ((volatile jint*)p)[1] = acc.words[1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  }
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   469
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  t->set_doing_unsafe_access(false);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   471
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   474
UNSAFE_LEAF(jlong, Unsafe_GetNativeAddress(JNIEnv *env, jobject unsafe, jlong addr)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  void* p = addr_from_java(addr);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   476
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  return addr_to_java(*(void**)p);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   478
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   480
UNSAFE_LEAF(void, Unsafe_SetNativeAddress(JNIEnv *env, jobject unsafe, jlong addr, jlong x)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  void* p = addr_from_java(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  *(void**)p = addr_from_java(x);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   483
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
////// Allocation requests
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   488
UNSAFE_ENTRY(jobject, Unsafe_AllocateInstance(JNIEnv *env, jobject unsafe, jclass cls)) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   489
  ThreadToNativeFromVM ttnfv(thread);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   490
  return env->AllocObject(cls);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   491
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   493
UNSAFE_ENTRY(jlong, Unsafe_AllocateMemory0(JNIEnv *env, jobject unsafe, jlong size)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  size_t sz = (size_t)size;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   495
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  sz = round_to(sz, HeapWordSize);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 10967
diff changeset
   497
  void* x = os::malloc(sz, mtInternal);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   498
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  return addr_to_java(x);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   500
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   502
UNSAFE_ENTRY(jlong, Unsafe_ReallocateMemory0(JNIEnv *env, jobject unsafe, jlong addr, jlong size)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  void* p = addr_from_java(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  size_t sz = (size_t)size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  sz = round_to(sz, HeapWordSize);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   506
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   507
  void* x = os::realloc(p, sz, mtInternal);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   508
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  return addr_to_java(x);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   510
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   512
UNSAFE_ENTRY(void, Unsafe_FreeMemory0(JNIEnv *env, jobject unsafe, jlong addr)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
  void* p = addr_from_java(addr);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   514
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  os::free(p);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   516
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   518
UNSAFE_ENTRY(void, Unsafe_SetMemory0(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong size, jbyte value)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  size_t sz = (size_t)size;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   520
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  oop base = JNIHandles::resolve(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  void* p = index_oop_from_field_offset_long(base, offset);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   523
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  Copy::fill_to_memory_atomic(p, sz, value);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   525
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   527
UNSAFE_ENTRY(void, Unsafe_CopyMemory0(JNIEnv *env, jobject unsafe, jobject srcObj, jlong srcOffset, jobject dstObj, jlong dstOffset, jlong size)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  size_t sz = (size_t)size;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   529
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  oop srcp = JNIHandles::resolve(srcObj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  oop dstp = JNIHandles::resolve(dstObj);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   532
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  void* src = index_oop_from_field_offset_long(srcp, srcOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  void* dst = index_oop_from_field_offset_long(dstp, dstOffset);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   535
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  Copy::conjoint_memory_atomic(src, dst, sz);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   537
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
36086
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   539
// This function is a leaf since if the source and destination are both in native memory
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   540
// the copy may potentially be very large, and we don't want to disable GC if we can avoid it.
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   541
// If either source or destination (or both) are on the heap, the function will enter VM using
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   542
// JVM_ENTRY_FROM_LEAF
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   543
UNSAFE_LEAF(void, Unsafe_CopySwapMemory0(JNIEnv *env, jobject unsafe, jobject srcObj, jlong srcOffset, jobject dstObj, jlong dstOffset, jlong size, jlong elemSize)) {
36086
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   544
  size_t sz = (size_t)size;
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   545
  size_t esz = (size_t)elemSize;
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   546
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   547
  if (srcObj == NULL && dstObj == NULL) {
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   548
    // Both src & dst are in native memory
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   549
    address src = (address)srcOffset;
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   550
    address dst = (address)dstOffset;
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   551
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   552
    Copy::conjoint_swap(src, dst, sz, esz);
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   553
  } else {
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   554
    // At least one of src/dst are on heap, transition to VM to access raw pointers
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   555
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   556
    JVM_ENTRY_FROM_LEAF(env, void, Unsafe_CopySwapMemory0) {
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   557
      oop srcp = JNIHandles::resolve(srcObj);
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   558
      oop dstp = JNIHandles::resolve(dstObj);
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   559
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   560
      address src = (address)index_oop_from_field_offset_long(srcp, srcOffset);
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   561
      address dst = (address)index_oop_from_field_offset_long(dstp, dstOffset);
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   562
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   563
      Copy::conjoint_swap(src, dst, sz, esz);
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   564
    } JVM_END
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
   565
  }
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   566
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
////// Random queries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   570
UNSAFE_LEAF(jint, Unsafe_AddressSize0(JNIEnv *env, jobject unsafe)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  return sizeof(void*);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   572
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   574
UNSAFE_LEAF(jint, Unsafe_PageSize()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  return os::vm_page_size();
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   576
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   578
static jint find_field_offset(jobject field, int must_be_static, TRAPS) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   579
  assert(field != NULL, "field must not be NULL");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  oop reflected   = JNIHandles::resolve_non_null(field);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  oop mirror      = java_lang_reflect_Field::clazz(reflected);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   583
  Klass* k        = java_lang_Class::as_Klass(mirror);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  int slot        = java_lang_reflect_Field::slot(reflected);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
  int modifiers   = java_lang_reflect_Field::modifiers(reflected);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
  if (must_be_static >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
    int really_is_static = ((modifiers & JVM_ACC_STATIC) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
    if (must_be_static != really_is_static) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
      THROW_0(vmSymbols::java_lang_IllegalArgumentException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   594
  int offset = InstanceKlass::cast(k)->field_offset(slot);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  return field_offset_from_byte_offset(offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   598
UNSAFE_ENTRY(jlong, Unsafe_ObjectFieldOffset0(JNIEnv *env, jobject unsafe, jobject field)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  return find_field_offset(field, 0, THREAD);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   600
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   602
UNSAFE_ENTRY(jlong, Unsafe_StaticFieldOffset0(JNIEnv *env, jobject unsafe, jobject field)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  return find_field_offset(field, 1, THREAD);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   604
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   606
UNSAFE_ENTRY(jobject, Unsafe_StaticFieldBase0(JNIEnv *env, jobject unsafe, jobject field)) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   607
  assert(field != NULL, "field must not be NULL");
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   608
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
  // Note:  In this VM implementation, a field address is always a short
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  // offset from the base of a a klass metaobject.  Thus, the full dynamic
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  // range of the return type is never used.  However, some implementations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  // might put the static field inside an array shared by many classes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
  // or even at a fixed address, in which case the address could be quite
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  // large.  In that last case, this function would return NULL, since
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
  // the address would operate alone, without any base pointer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
  oop reflected   = JNIHandles::resolve_non_null(field);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
  oop mirror      = java_lang_reflect_Field::clazz(reflected);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
  int modifiers   = java_lang_reflect_Field::modifiers(reflected);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
  if ((modifiers & JVM_ACC_STATIC) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
    THROW_0(vmSymbols::java_lang_IllegalArgumentException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
8725
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 8490
diff changeset
   625
  return JNIHandles::make_local(env, mirror);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   626
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   628
UNSAFE_ENTRY(void, Unsafe_EnsureClassInitialized0(JNIEnv *env, jobject unsafe, jobject clazz)) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   629
  assert(clazz != NULL, "clazz must not be NULL");
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   630
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
  oop mirror = JNIHandles::resolve_non_null(clazz);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13295
diff changeset
   632
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   633
  Klass* klass = java_lang_Class::as_Klass(mirror);
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14127
diff changeset
   634
  if (klass != NULL && klass->should_be_initialized()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   635
    InstanceKlass* k = InstanceKlass::cast(klass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
    k->initialize(CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13295
diff changeset
   638
}
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13295
diff changeset
   639
UNSAFE_END
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13295
diff changeset
   640
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   641
UNSAFE_ENTRY(jboolean, Unsafe_ShouldBeInitialized0(JNIEnv *env, jobject unsafe, jobject clazz)) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   642
  assert(clazz != NULL, "clazz must not be NULL");
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   643
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13295
diff changeset
   644
  oop mirror = JNIHandles::resolve_non_null(clazz);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   645
  Klass* klass = java_lang_Class::as_Klass(mirror);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   646
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14127
diff changeset
   647
  if (klass != NULL && klass->should_be_initialized()) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13295
diff changeset
   648
    return true;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13295
diff changeset
   649
  }
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   650
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13295
diff changeset
   651
  return false;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13295
diff changeset
   652
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
UNSAFE_END
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   655
static void getBaseAndScale(int& base, int& scale, jclass clazz, TRAPS) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   656
  assert(clazz != NULL, "clazz must not be NULL");
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   657
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   658
  oop mirror = JNIHandles::resolve_non_null(clazz);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   659
  Klass* k = java_lang_Class::as_Klass(mirror);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   660
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33589
diff changeset
   661
  if (k == NULL || !k->is_array_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
    THROW(vmSymbols::java_lang_InvalidClassException());
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33589
diff changeset
   663
  } else if (k->is_objArray_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
    base  = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   665
    scale = heapOopSize;
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33589
diff changeset
   666
  } else if (k->is_typeArray_klass()) {
13952
e3cf184080bc 8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents: 13728
diff changeset
   667
    TypeArrayKlass* tak = TypeArrayKlass::cast(k);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
    base  = tak->array_header_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
    assert(base == arrayOopDesc::base_offset_in_bytes(tak->element_type()), "array_header_size semantics ok");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
    scale = (1 << tak->log2_element_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   676
UNSAFE_ENTRY(jint, Unsafe_ArrayBaseOffset0(JNIEnv *env, jobject unsafe, jclass clazz)) {
33589
7cbd1b2c139b 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents: 33148
diff changeset
   677
  int base = 0, scale = 0;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   678
  getBaseAndScale(base, scale, clazz, CHECK_0);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   679
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
  return field_offset_from_byte_offset(base);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   681
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   684
UNSAFE_ENTRY(jint, Unsafe_ArrayIndexScale0(JNIEnv *env, jobject unsafe, jclass clazz)) {
33589
7cbd1b2c139b 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents: 33148
diff changeset
   685
  int base = 0, scale = 0;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   686
  getBaseAndScale(base, scale, clazz, CHECK_0);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   687
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
  // This VM packs both fields and array elements down to the byte.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  // But watch out:  If this changes, so that array references for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
  // a given primitive type (say, T_BOOLEAN) use different memory units
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
  // than fields, this method MUST return zero for such arrays.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
  // For example, the VM used to store sub-word sized fields in full
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
  // words in the object layout, so that accessors like getByte(Object,int)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
  // did not really do what one might expect for arrays.  Therefore,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
  // this function used to report a zero scale factor, so that the user
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  // would know not to attempt to access sub-word array elements.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  // // Code for unpacked fields:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  // if (scale < wordSize)  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
  // The following allows for a pretty general fieldOffset cookie scheme,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  // but requires it to be linear in byte offset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
  return field_offset_from_byte_offset(scale) - field_offset_from_byte_offset(0);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   703
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
static inline void throw_new(JNIEnv *env, const char *ename) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  char buf[100];
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   708
27471
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 25715
diff changeset
   709
  jio_snprintf(buf, 100, "%s%s", "java/lang/", ename);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   710
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  jclass cls = env->FindClass(buf);
22786
86644d9539c2 8028785: [parfait] warnings from b116 for hotspot.src.share.vm.prims: JNI exception pending
ccheung
parents: 20282
diff changeset
   712
  if (env->ExceptionCheck()) {
86644d9539c2 8028785: [parfait] warnings from b116 for hotspot.src.share.vm.prims: JNI exception pending
ccheung
parents: 20282
diff changeset
   713
    env->ExceptionClear();
86644d9539c2 8028785: [parfait] warnings from b116 for hotspot.src.share.vm.prims: JNI exception pending
ccheung
parents: 20282
diff changeset
   714
    tty->print_cr("Unsafe: cannot throw %s because FindClass has failed", buf);
86644d9539c2 8028785: [parfait] warnings from b116 for hotspot.src.share.vm.prims: JNI exception pending
ccheung
parents: 20282
diff changeset
   715
    return;
86644d9539c2 8028785: [parfait] warnings from b116 for hotspot.src.share.vm.prims: JNI exception pending
ccheung
parents: 20282
diff changeset
   716
  }
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   717
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   718
  env->ThrowNew(cls, NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
16617
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 15482
diff changeset
   721
static jclass Unsafe_DefineClass_impl(JNIEnv *env, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd) {
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   722
  // Code lifted from JDK 1.3 ClassLoader.c
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   723
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   724
  jbyte *body;
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   725
  char *utfName = NULL;
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   726
  jclass result = 0;
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   727
  char buf[128];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   729
  assert(data != NULL, "Class bytes must not be NULL");
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   730
  assert(length >= 0, "length must not be negative: %d", length);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   732
  if (UsePerfData) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   733
    ClassLoader::unsafe_defineClassCallCounter()->inc();
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   734
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   736
  body = NEW_C_HEAP_ARRAY(jbyte, length, mtInternal);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   737
  if (body == NULL) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   738
    throw_new(env, "OutOfMemoryError");
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   739
    return 0;
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   740
  }
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   741
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   742
  env->GetByteArrayRegion(data, offset, length, body);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   743
  if (env->ExceptionOccurred()) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   744
    goto free_body;
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   745
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   747
  if (name != NULL) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   748
    uint len = env->GetStringUTFLength(name);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   749
    int unicode_len = env->GetStringLength(name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   751
    if (len >= sizeof(buf)) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   752
      utfName = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   753
      if (utfName == NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
        throw_new(env, "OutOfMemoryError");
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   755
        goto free_body;
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   756
      }
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   757
    } else {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   758
      utfName = buf;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   761
    env->GetStringUTFRegion(name, 0, unicode_len, utfName);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   763
    for (uint i = 0; i < len; i++) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   764
      if (utfName[i] == '.')   utfName[i] = '/';
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
    }
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   766
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   768
  result = JVM_DefineClass(env, utfName, loader, body, length, pd);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   770
  if (utfName && utfName != buf) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   771
    FREE_C_HEAP_ARRAY(char, utfName);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   772
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
 free_body:
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   775
  FREE_C_HEAP_ARRAY(jbyte, body);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   776
  return result;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   780
UNSAFE_ENTRY(jclass, Unsafe_DefineClass0(JNIEnv *env, jobject unsafe, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd)) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   781
  ThreadToNativeFromVM ttnfv(thread);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   782
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   783
  return Unsafe_DefineClass_impl(env, name, data, offset, length, loader, pd);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   784
} UNSAFE_END
16617
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 15482
diff changeset
   785
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 15482
diff changeset
   786
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   787
// define a class but do not make it known to the class loader or system dictionary
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   788
// - host_class:  supplies context for linkage, access control, protection domain, and class loader
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   789
// - data:  bytes of a class file, a raw memory address (length gives the number of bytes)
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   790
// - cp_patches:  where non-null entries exist, they replace corresponding CP entries in data
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   791
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   792
// When you load an anonymous class U, it works as if you changed its name just before loading,
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   793
// to a name that you will never use again.  Since the name is lost, no other class can directly
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   794
// link to any member of U.  Just after U is loaded, the only way to use it is reflectively,
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   795
// through java.lang.Class methods like Class.newInstance.
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   796
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   797
// Access checks for linkage sites within U continue to follow the same rules as for named classes.
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   798
// The package of an anonymous class is given by the package qualifier on the name under which it was loaded.
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   799
// An anonymous class also has special privileges to access any member of its host class.
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   800
// This is the main reason why this loading operation is unsafe.  The purpose of this is to
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   801
// allow language implementations to simulate "open classes"; a host class in effect gets
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   802
// new code when an anonymous class is loaded alongside it.  A less convenient but more
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   803
// standard way to do this is with reflection, which can also be set to ignore access
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   804
// restrictions.
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   805
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   806
// Access into an anonymous class is possible only through reflection.  Therefore, there
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   807
// are no special access rules for calling into an anonymous class.  The relaxed access
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   808
// rule for the host class is applied in the opposite direction:  A host class reflectively
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   809
// access one of its anonymous classes.
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   810
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   811
// If you load the same bytecodes twice, you get two different classes.  You can reload
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   812
// the same bytecodes with or without varying CP patches.
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   813
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   814
// By using the CP patching array, you can have a new anonymous class U2 refer to an older one U1.
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   815
// The bytecodes for U2 should refer to U1 by a symbolic name (doesn't matter what the name is).
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   816
// The CONSTANT_Class entry for that name can be patched to refer directly to U1.
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   817
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   818
// This allows, for example, U2 to use U1 as a superclass or super-interface, or as
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   819
// an outer class (so that U2 is an anonymous inner class of anonymous U1).
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   820
// It is not possible for a named class, or an older anonymous class, to refer by
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   821
// name (via its CP) to a newer anonymous class.
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   822
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   823
// CP patching may also be used to modify (i.e., hack) the names of methods, classes,
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   824
// or type descriptors used in the loaded anonymous class.
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   825
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   826
// Finally, CP patching may be used to introduce "live" objects into the constant pool,
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   827
// instead of "dead" strings.  A compiled statement like println((Object)"hello") can
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   828
// be changed to println(greeting), where greeting is an arbitrary object created before
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   829
// the anonymous class is loaded.  This is useful in dynamic languages, in which
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   830
// various kinds of metaobjects must be introduced as constants into bytecode.
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   831
// Note the cast (Object), which tells the verifier to expect an arbitrary object,
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   832
// not just a literal string.  For such ldc instructions, the verifier uses the
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   833
// type Object instead of String, if the loaded constant is not in fact a String.
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   834
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   835
static instanceKlassHandle
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   836
Unsafe_DefineAnonymousClass_impl(JNIEnv *env,
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   837
                                 jclass host_class, jbyteArray data, jobjectArray cp_patches_jh,
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   838
                                 u1** temp_alloc,
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   839
                                 TRAPS) {
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   840
  assert(host_class != NULL, "host_class must not be NULL");
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   841
  assert(data != NULL, "data must not be NULL");
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   842
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   843
  if (UsePerfData) {
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   844
    ClassLoader::unsafe_defineClassCallCounter()->inc();
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   845
  }
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   846
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   847
  jint length = typeArrayOop(JNIHandles::resolve_non_null(data))->length();
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   848
  assert(length >= 0, "class_bytes_length must not be negative: %d", length);
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   849
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   850
  int class_bytes_length = (int) length;
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   851
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   852
  u1* class_bytes = NEW_C_HEAP_ARRAY(u1, length, mtInternal);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   853
  if (class_bytes == NULL) {
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   854
    THROW_0(vmSymbols::java_lang_OutOfMemoryError());
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   855
  }
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   856
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   857
  // caller responsible to free it:
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   858
  *temp_alloc = class_bytes;
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   859
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   860
  jbyte* array_base = typeArrayOop(JNIHandles::resolve_non_null(data))->byte_at_addr(0);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   861
  Copy::conjoint_jbytes(array_base, class_bytes, length);
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   862
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   863
  objArrayHandle cp_patches_h;
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   864
  if (cp_patches_jh != NULL) {
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   865
    oop p = JNIHandles::resolve_non_null(cp_patches_jh);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   866
    assert(p->is_objArray(), "cp_patches must be an object[]");
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   867
    cp_patches_h = objArrayHandle(THREAD, (objArrayOop)p);
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   868
  }
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   869
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 33612
diff changeset
   870
  const Klass* host_klass = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(host_class));
37184
23e0d47c1f3e 8140665: SIGSEGV when a primitive type's class is used as the host class in a call to DefineAnonymousClass call
hseigel
parents: 36551
diff changeset
   871
  // Primitive types have NULL Klass* fields in their java.lang.Class instances.
23e0d47c1f3e 8140665: SIGSEGV when a primitive type's class is used as the host class in a call to DefineAnonymousClass call
hseigel
parents: 36551
diff changeset
   872
  if (host_klass == NULL) {
23e0d47c1f3e 8140665: SIGSEGV when a primitive type's class is used as the host class in a call to DefineAnonymousClass call
hseigel
parents: 36551
diff changeset
   873
    THROW_0(vmSymbols::java_lang_IllegalArgumentException());
23e0d47c1f3e 8140665: SIGSEGV when a primitive type's class is used as the host class in a call to DefineAnonymousClass call
hseigel
parents: 36551
diff changeset
   874
  }
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 33612
diff changeset
   875
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   876
  const char* host_source = host_klass->external_name();
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   877
  Handle      host_loader(THREAD, host_klass->class_loader());
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   878
  Handle      host_domain(THREAD, host_klass->protection_domain());
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   879
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   880
  GrowableArray<Handle>* cp_patches = NULL;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   881
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   882
  if (cp_patches_h.not_null()) {
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   883
    int alen = cp_patches_h->length();
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   884
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   885
    for (int i = alen-1; i >= 0; i--) {
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   886
      oop p = cp_patches_h->obj_at(i);
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   887
      if (p != NULL) {
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   888
        Handle patch(THREAD, p);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   889
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   890
        if (cp_patches == NULL) {
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   891
          cp_patches = new GrowableArray<Handle>(i+1, i+1, Handle());
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   892
        }
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   893
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   894
        cp_patches->at_put(i, patch);
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   895
      }
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   896
    }
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   897
  }
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   898
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   899
  ClassFileStream st(class_bytes, class_bytes_length, host_source, ClassFileStream::verify);
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   900
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   901
  Symbol* no_class_name = NULL;
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   902
  Klass* anonk = SystemDictionary::parse_stream(no_class_name,
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   903
                                                host_loader,
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   904
                                                host_domain,
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   905
                                                &st,
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   906
                                                host_klass,
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   907
                                                cp_patches,
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   908
                                                CHECK_NULL);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   909
  if (anonk == NULL) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   910
    return NULL;
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   911
  }
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   912
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   913
  return instanceKlassHandle(THREAD, anonk);
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   914
}
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   915
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   916
UNSAFE_ENTRY(jclass, Unsafe_DefineAnonymousClass0(JNIEnv *env, jobject unsafe, jclass host_class, jbyteArray data, jobjectArray cp_patches_jh)) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   917
  ResourceMark rm(THREAD);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   918
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   919
  instanceKlassHandle anon_klass;
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   920
  jobject res_jh = NULL;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   921
  u1* temp_alloc = NULL;
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   922
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   923
  anon_klass = Unsafe_DefineAnonymousClass_impl(env, host_class, data, cp_patches_jh, &temp_alloc, THREAD);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   924
  if (anon_klass() != NULL) {
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   925
    res_jh = JNIHandles::make_local(env, anon_klass->java_mirror());
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   926
  }
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   927
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   928
  // try/finally clause:
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   929
  if (temp_alloc != NULL) {
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   930
    FREE_C_HEAP_ARRAY(u1, temp_alloc);
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   931
  }
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   932
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   933
  // The anonymous class loader data has been artificially been kept alive to
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   934
  // this point.   The mirror and any instances of this class have to keep
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   935
  // it alive afterwards.
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   936
  if (anon_klass() != NULL) {
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   937
    anon_klass->class_loader_data()->set_keep_alive(false);
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   938
  }
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   939
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   940
  // let caller initialize it as needed...
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14488
diff changeset
   941
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   942
  return (jclass) res_jh;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   943
} UNSAFE_END
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   944
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 1388
diff changeset
   945
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   947
UNSAFE_ENTRY(void, Unsafe_ThrowException(JNIEnv *env, jobject unsafe, jthrowable thr)) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   948
  ThreadToNativeFromVM ttnfv(thread);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   949
  env->Throw(thr);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   950
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
// JSR166 ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   954
UNSAFE_ENTRY(jobject, Unsafe_CompareAndExchangeObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject e_h, jobject x_h)) {
36316
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   955
  oop x = JNIHandles::resolve(x_h);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   956
  oop e = JNIHandles::resolve(e_h);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   957
  oop p = JNIHandles::resolve(obj);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   958
  HeapWord* addr = (HeapWord *)index_oop_from_field_offset_long(p, offset);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   959
  oop res = oopDesc::atomic_compare_exchange_oop(x, addr, e, true);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   960
  if (res == e) {
36316
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   961
    update_barrier_set((void*)addr, x);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   962
  }
36316
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   963
  return JNIHandles::make_local(env, res);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   964
} UNSAFE_END
36316
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   965
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   966
UNSAFE_ENTRY(jint, Unsafe_CompareAndExchangeInt(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jint e, jint x)) {
36316
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   967
  oop p = JNIHandles::resolve(obj);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   968
  jint* addr = (jint *) index_oop_from_field_offset_long(p, offset);
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   969
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   970
  return (jint)(Atomic::cmpxchg(x, addr, e));
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   971
} UNSAFE_END
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   972
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   973
UNSAFE_ENTRY(jlong, Unsafe_CompareAndExchangeLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong e, jlong x)) {
36316
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   974
  Handle p (THREAD, JNIHandles::resolve(obj));
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   975
  jlong* addr = (jlong*)(index_oop_from_field_offset_long(p(), offset));
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   976
36316
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   977
#ifdef SUPPORTS_NATIVE_CX8
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   978
  return (jlong)(Atomic::cmpxchg(x, addr, e));
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   979
#else
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   980
  if (VM_Version::supports_cx8()) {
36316
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   981
    return (jlong)(Atomic::cmpxchg(x, addr, e));
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   982
  } else {
36316
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   983
    MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   984
36316
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   985
    jlong val = Atomic::load(addr);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   986
    if (val == e) {
36316
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   987
      Atomic::store(x, addr);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   988
    }
36316
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   989
    return val;
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   990
  }
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   991
#endif
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   992
} UNSAFE_END
36316
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
   993
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
   994
UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jobject e_h, jobject x_h)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
  oop x = JNIHandles::resolve(x_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
  oop e = JNIHandles::resolve(e_h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
  oop p = JNIHandles::resolve(obj);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   998
  HeapWord* addr = (HeapWord *)index_oop_from_field_offset_long(p, offset);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   999
  oop res = oopDesc::atomic_compare_exchange_oop(x, addr, e, true);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1000
  if (res != e) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1001
    return false;
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1002
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1004
  update_barrier_set((void*)addr, x);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1005
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1006
  return true;
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1007
} UNSAFE_END
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1008
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1009
UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapInt(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jint e, jint x)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
  oop p = JNIHandles::resolve(obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
  jint* addr = (jint *) index_oop_from_field_offset_long(p, offset);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1012
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
  return (jint)(Atomic::cmpxchg(x, addr, e)) == e;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1014
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1016
UNSAFE_ENTRY(jboolean, Unsafe_CompareAndSwapLong(JNIEnv *env, jobject unsafe, jobject obj, jlong offset, jlong e, jlong x)) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1017
  Handle p(THREAD, JNIHandles::resolve(obj));
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1018
  jlong* addr = (jlong*)index_oop_from_field_offset_long(p(), offset);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1019
27874
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
  1020
#ifdef SUPPORTS_NATIVE_CX8
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
  1021
  return (jlong)(Atomic::cmpxchg(x, addr, e)) == e;
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
  1022
#else
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1023
  if (VM_Version::supports_cx8()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
    return (jlong)(Atomic::cmpxchg(x, addr, e)) == e;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1025
  } else {
27874
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
  1026
    MutexLockerEx mu(UnsafeJlong_lock, Mutex::_no_safepoint_check_flag);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1027
27874
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
  1028
    jlong val = Atomic::load(addr);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1029
    if (val != e) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1030
      return false;
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1031
    }
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1032
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1033
    Atomic::store(x, addr);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1034
    return true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
  }
27874
e9b44eb1613f 8035663: Suspicious failure of test java/util/concurrent/Phaser/FickleRegister.java
dholmes
parents: 27471
diff changeset
  1036
#endif
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1037
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1039
UNSAFE_ENTRY(void, Unsafe_Park(JNIEnv *env, jobject unsafe, jboolean isAbsolute, jlong time)) {
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17881
diff changeset
  1040
  EventThreadPark event;
22796
bb0ea482a99e 8034080: Remove the USDT1 dtrace code from Hotspot
sla
parents: 22786
diff changeset
  1041
  HOTSPOT_THREAD_PARK_BEGIN((uintptr_t) thread->parker(), (int) isAbsolute, time);
bb0ea482a99e 8034080: Remove the USDT1 dtrace code from Hotspot
sla
parents: 22786
diff changeset
  1042
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
  JavaThreadParkedState jtps(thread, time != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
  thread->parker()->park(isAbsolute != 0, time);
22796
bb0ea482a99e 8034080: Remove the USDT1 dtrace code from Hotspot
sla
parents: 22786
diff changeset
  1045
bb0ea482a99e 8034080: Remove the USDT1 dtrace code from Hotspot
sla
parents: 22786
diff changeset
  1046
  HOTSPOT_THREAD_PARK_END((uintptr_t) thread->parker());
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1047
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17881
diff changeset
  1048
  if (event.should_commit()) {
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17881
diff changeset
  1049
    oop obj = thread->current_park_blocker();
20282
7f9cbdf89af2 7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents: 18025
diff changeset
  1050
    event.set_klass((obj != NULL) ? obj->klass() : NULL);
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17881
diff changeset
  1051
    event.set_timeout(time);
20282
7f9cbdf89af2 7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents: 18025
diff changeset
  1052
    event.set_address((obj != NULL) ? (TYPE_ADDRESS) cast_from_oop<uintptr_t>(obj) : 0);
18025
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17881
diff changeset
  1053
    event.commit();
b7bcf7497f93 8005849: JEP 167: Event-Based JVM Tracing
sla
parents: 17881
diff changeset
  1054
  }
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1055
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1057
UNSAFE_ENTRY(void, Unsafe_Unpark(JNIEnv *env, jobject unsafe, jobject jthread)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
  Parker* p = NULL;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1059
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
  if (jthread != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
    oop java_thread = JNIHandles::resolve_non_null(jthread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
    if (java_thread != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
      jlong lp = java_lang_Thread::park_event(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
      if (lp != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
        // This cast is OK even though the jlong might have been read
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
        // non-atomically on 32bit systems, since there, one word will
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
        // always be zero anyway and the value set is always the same
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
        p = (Parker*)addr_from_java(lp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
        // Grab lock if apparently null or using older version of library
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
        MutexLocker mu(Threads_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
        java_thread = JNIHandles::resolve_non_null(jthread);
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1073
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
        if (java_thread != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
          JavaThread* thr = java_lang_Thread::thread(java_thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
          if (thr != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
            p = thr->parker();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
            if (p != NULL) { // Bind to Java thread for next time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
              java_lang_Thread::set_park_event(java_thread, addr_to_java(p));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
  }
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1086
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
  if (p != NULL) {
22796
bb0ea482a99e 8034080: Remove the USDT1 dtrace code from Hotspot
sla
parents: 22786
diff changeset
  1088
    HOTSPOT_THREAD_UNPARK((uintptr_t) p);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
    p->unpark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
  }
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1091
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1093
UNSAFE_ENTRY(jint, Unsafe_GetLoadAverage0(JNIEnv *env, jobject unsafe, jdoubleArray loadavg, jint nelem)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
  const int max_nelem = 3;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
  double la[max_nelem];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
  jint ret;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
  typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(loadavg));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
  assert(a->is_typeArray(), "must be type array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1101
  ret = os::loadavg(la, nelem);
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1102
  if (ret == -1) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
  // if successful, ret is the number of samples actually retrieved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
  assert(ret >= 0 && ret <= max_nelem, "Unexpected loadavg return value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
  switch(ret) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
    case 3: a->double_at_put(2, (jdouble)la[2]); // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
    case 2: a->double_at_put(1, (jdouble)la[1]); // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
    case 1: a->double_at_put(0, (jdouble)la[0]); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
  }
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1113
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
  return ret;
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1115
} UNSAFE_END
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
/// JVM_RegisterUnsafeMethods
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
#define ADR "J"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
#define LANG "Ljava/lang/"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1124
#define OBJ LANG "Object;"
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1125
#define CLS LANG "Class;"
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1126
#define FLD LANG "reflect/Field;"
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1127
#define THR LANG "Throwable;"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1129
#define DC_Args  LANG "String;[BII" LANG "ClassLoader;" "Ljava/security/ProtectionDomain;"
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1130
#define DAC_Args CLS "[B[" OBJ
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
#define CC (char*)  /*cast a literal from (const char*)*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1135
#define DECLARE_GETPUTOOP(Type, Desc) \
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1136
    {CC "get" #Type,      CC "(" OBJ "J)" #Desc,       FN_PTR(Unsafe_Get##Type)}, \
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1137
    {CC "put" #Type,      CC "(" OBJ "J" #Desc ")V",   FN_PTR(Unsafe_Set##Type)}, \
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1138
    {CC "get" #Type "Volatile",      CC "(" OBJ "J)" #Desc,       FN_PTR(Unsafe_Get##Type##Volatile)}, \
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1139
    {CC "put" #Type "Volatile",      CC "(" OBJ "J" #Desc ")V",   FN_PTR(Unsafe_Set##Type##Volatile)}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
28951
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1142
#define DECLARE_GETPUTNATIVE(Byte, B) \
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1143
    {CC "get" #Byte,         CC "(" ADR ")" #B,       FN_PTR(Unsafe_GetNative##Byte)}, \
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1144
    {CC "put" #Byte,         CC "(" ADR#B ")V",       FN_PTR(Unsafe_SetNative##Byte)}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
35103
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 33612
diff changeset
  1146
static JNINativeMethod jdk_internal_misc_Unsafe_methods[] = {
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1147
    {CC "getObject",        CC "(" OBJ "J)" OBJ "",   FN_PTR(Unsafe_GetObject)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1148
    {CC "putObject",        CC "(" OBJ "J" OBJ ")V",  FN_PTR(Unsafe_SetObject)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1149
    {CC "getObjectVolatile",CC "(" OBJ "J)" OBJ "",   FN_PTR(Unsafe_GetObjectVolatile)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1150
    {CC "putObjectVolatile",CC "(" OBJ "J" OBJ ")V",  FN_PTR(Unsafe_SetObjectVolatile)},
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1152
    {CC "getUncompressedObject", CC "(" ADR ")" OBJ,  FN_PTR(Unsafe_GetUncompressedObject)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1153
    {CC "getJavaMirror",         CC "(" ADR ")" CLS,  FN_PTR(Unsafe_GetJavaMirror)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1154
    {CC "getKlassPointer",       CC "(" OBJ ")" ADR,  FN_PTR(Unsafe_GetKlassPointer)},
30288
476c276de939 8022853: add ability to load uncompressed object and Klass references in a compressed environment to Unsafe
twisti
parents: 30209
diff changeset
  1155
28951
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1156
    DECLARE_GETPUTOOP(Boolean, Z),
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1157
    DECLARE_GETPUTOOP(Byte, B),
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1158
    DECLARE_GETPUTOOP(Short, S),
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1159
    DECLARE_GETPUTOOP(Char, C),
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1160
    DECLARE_GETPUTOOP(Int, I),
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1161
    DECLARE_GETPUTOOP(Long, J),
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1162
    DECLARE_GETPUTOOP(Float, F),
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1163
    DECLARE_GETPUTOOP(Double, D),
16617
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 15482
diff changeset
  1164
28951
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1165
    DECLARE_GETPUTNATIVE(Byte, B),
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1166
    DECLARE_GETPUTNATIVE(Short, S),
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1167
    DECLARE_GETPUTNATIVE(Char, C),
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1168
    DECLARE_GETPUTNATIVE(Int, I),
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1169
    DECLARE_GETPUTNATIVE(Long, J),
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1170
    DECLARE_GETPUTNATIVE(Float, F),
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1171
    DECLARE_GETPUTNATIVE(Double, D),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1173
    {CC "getAddress",         CC "(" ADR ")" ADR,        FN_PTR(Unsafe_GetNativeAddress)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1174
    {CC "putAddress",         CC "(" ADR "" ADR ")V",    FN_PTR(Unsafe_SetNativeAddress)},
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1176
    {CC "allocateMemory0",    CC "(J)" ADR,              FN_PTR(Unsafe_AllocateMemory0)},
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1177
    {CC "reallocateMemory0",  CC "(" ADR "J)" ADR,       FN_PTR(Unsafe_ReallocateMemory0)},
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1178
    {CC "freeMemory0",        CC "(" ADR ")V",           FN_PTR(Unsafe_FreeMemory0)},
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1180
    {CC "objectFieldOffset0", CC "(" FLD ")J",           FN_PTR(Unsafe_ObjectFieldOffset0)},
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1181
    {CC "staticFieldOffset0", CC "(" FLD ")J",           FN_PTR(Unsafe_StaticFieldOffset0)},
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1182
    {CC "staticFieldBase0",   CC "(" FLD ")" OBJ,        FN_PTR(Unsafe_StaticFieldBase0)},
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1183
    {CC "ensureClassInitialized0", CC "(" CLS ")V",      FN_PTR(Unsafe_EnsureClassInitialized0)},
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1184
    {CC "arrayBaseOffset0",   CC "(" CLS ")I",           FN_PTR(Unsafe_ArrayBaseOffset0)},
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1185
    {CC "arrayIndexScale0",   CC "(" CLS ")I",           FN_PTR(Unsafe_ArrayIndexScale0)},
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1186
    {CC "addressSize0",       CC "()I",                  FN_PTR(Unsafe_AddressSize0)},
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1187
    {CC "pageSize",           CC "()I",                  FN_PTR(Unsafe_PageSize)},
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1189
    {CC "defineClass0",       CC "(" DC_Args ")" CLS,    FN_PTR(Unsafe_DefineClass0)},
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1190
    {CC "allocateInstance",   CC "(" CLS ")" OBJ,        FN_PTR(Unsafe_AllocateInstance)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1191
    {CC "throwException",     CC "(" THR ")V",           FN_PTR(Unsafe_ThrowException)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1192
    {CC "compareAndSwapObject", CC "(" OBJ "J" OBJ "" OBJ ")Z", FN_PTR(Unsafe_CompareAndSwapObject)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1193
    {CC "compareAndSwapInt",  CC "(" OBJ "J""I""I"")Z",  FN_PTR(Unsafe_CompareAndSwapInt)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1194
    {CC "compareAndSwapLong", CC "(" OBJ "J""J""J"")Z",  FN_PTR(Unsafe_CompareAndSwapLong)},
36316
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
  1195
    {CC "compareAndExchangeObjectVolatile", CC "(" OBJ "J" OBJ "" OBJ ")" OBJ, FN_PTR(Unsafe_CompareAndExchangeObject)},
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
  1196
    {CC "compareAndExchangeIntVolatile",  CC "(" OBJ "J""I""I"")I", FN_PTR(Unsafe_CompareAndExchangeInt)},
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
  1197
    {CC "compareAndExchangeLongVolatile", CC "(" OBJ "J""J""J"")J", FN_PTR(Unsafe_CompareAndExchangeLong)},
7a83de7aabca 8148146: Integrate new internal Unsafe entry points, and basic intrinsic support for VarHandles
shade
parents: 36086
diff changeset
  1198
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1199
    {CC "park",               CC "(ZJ)V",                FN_PTR(Unsafe_Park)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1200
    {CC "unpark",             CC "(" OBJ ")V",           FN_PTR(Unsafe_Unpark)},
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1202
    {CC "getLoadAverage0",    CC "([DI)I",               FN_PTR(Unsafe_GetLoadAverage0)},
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1204
    {CC "copyMemory0",        CC "(" OBJ "J" OBJ "JJ)V", FN_PTR(Unsafe_CopyMemory0)},
36086
f70e100d3195 8141491: Unaligned memory access in Bits.c
mikael
parents: 35135
diff changeset
  1205
    {CC "copySwapMemory0",    CC "(" OBJ "J" OBJ "JJJ)V", FN_PTR(Unsafe_CopySwapMemory0)},
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1206
    {CC "setMemory0",         CC "(" OBJ "JJB)V",        FN_PTR(Unsafe_SetMemory0)},
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1208
    {CC "defineAnonymousClass0", CC "(" DAC_Args ")" CLS, FN_PTR(Unsafe_DefineAnonymousClass0)},
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1209
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1210
    {CC "shouldBeInitialized0", CC "(" CLS ")Z",         FN_PTR(Unsafe_ShouldBeInitialized0)},
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13295
diff changeset
  1211
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1212
    {CC "loadFence",          CC "()V",                  FN_PTR(Unsafe_LoadFence)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1213
    {CC "storeFence",         CC "()V",                  FN_PTR(Unsafe_StoreFence)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1214
    {CC "fullFence",          CC "()V",                  FN_PTR(Unsafe_FullFence)},
30209
8ea30dc99369 8026049: (bf) Intrinsify ByteBuffer.put{Int, Double, Float, ...} methods
aph
parents: 29083
diff changeset
  1215
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1216
    {CC "isBigEndian0",       CC "()Z",                  FN_PTR(Unsafe_isBigEndian0)},
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
  1217
    {CC "unalignedAccess0",   CC "()Z",                  FN_PTR(Unsafe_unalignedAccess0)}
16617
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 15482
diff changeset
  1218
};
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 15482
diff changeset
  1219
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
#undef CC
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
#undef FN_PTR
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
#undef ADR
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
#undef LANG
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
#undef OBJ
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1226
#undef CLS
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
#undef FLD
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
#undef THR
16617
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 15482
diff changeset
  1229
#undef DC_Args
28951
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1230
#undef DAC_Args
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
28951
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1232
#undef DECLARE_GETPUTOOP
a29d2048e16a 8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents: 28621
diff changeset
  1233
#undef DECLARE_GETPUTNATIVE
16617
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 15482
diff changeset
  1234
6235d2c7549f 7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents: 15482
diff changeset
  1235
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1236
// This function is exported, used by NativeLookup.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
// The Unsafe_xxx functions above are called only from the interpreter.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
// The optimizer looks at names and signatures to recognize
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
// individual functions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1241
JVM_ENTRY(void, JVM_RegisterJDKInternalMiscUnsafeMethods(JNIEnv *env, jclass unsafeclass)) {
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1242
  ThreadToNativeFromVM ttnfv(thread);
35103
d19354bcbfa6 8143628: Fork sun.misc.Unsafe and jdk.internal.misc.Unsafe native method tables
psandoz
parents: 33612
diff changeset
  1243
36551
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1244
  int ok = env->RegisterNatives(unsafeclass, jdk_internal_misc_Unsafe_methods, sizeof(jdk_internal_misc_Unsafe_methods)/sizeof(JNINativeMethod));
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1245
  guarantee(ok == 0, "register jdk.internal.misc.Unsafe natives");
77f29c57ed2e 8149159: Clean up Unsafe
mikael
parents: 36316
diff changeset
  1246
} JVM_END