author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58299 | 6df94ce3ab2f |
permissions | -rw-r--r-- |
47084 | 1 |
/* |
58299 | 2 |
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
47084 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
50858 | 23 |
|
24 |
||
47084 | 25 |
package org.graalvm.compiler.hotspot.meta; |
26 |
||
55674
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
27 |
import static org.graalvm.compiler.hotspot.GraalHotSpotVMConfig.INJECTED_VMCONFIG; |
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
28 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.doingUnsafeAccessOffset; |
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
29 |
|
47084 | 30 |
import org.graalvm.compiler.api.replacements.ClassSubstitution; |
31 |
import org.graalvm.compiler.api.replacements.MethodSubstitution; |
|
32 |
import org.graalvm.compiler.hotspot.HotSpotBackend; |
|
55674
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
33 |
import org.graalvm.compiler.hotspot.nodes.CurrentJavaThreadNode; |
52910 | 34 |
import org.graalvm.compiler.nodes.ComputeObjectAddressNode; |
55509 | 35 |
import org.graalvm.compiler.serviceprovider.JavaVersionUtil; |
47084 | 36 |
import org.graalvm.compiler.word.Word; |
55674
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
37 |
import jdk.internal.vm.compiler.word.LocationIdentity; |
49873 | 38 |
import jdk.internal.vm.compiler.word.WordFactory; |
47084 | 39 |
|
40 |
@ClassSubstitution(className = {"jdk.internal.misc.Unsafe", "sun.misc.Unsafe"}) |
|
41 |
public class HotSpotUnsafeSubstitutions { |
|
42 |
||
55509 | 43 |
public static final String copyMemoryName = JavaVersionUtil.JAVA_SPEC <= 8 ? "copyMemory" : "copyMemory0"; |
47084 | 44 |
|
45 |
@SuppressWarnings("unused") |
|
46 |
@MethodSubstitution(isStatic = false) |
|
47 |
static void copyMemory(Object receiver, Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes) { |
|
48 |
Word srcAddr = WordFactory.unsigned(ComputeObjectAddressNode.get(srcBase, srcOffset)); |
|
49 |
Word dstAddr = WordFactory.unsigned(ComputeObjectAddressNode.get(destBase, destOffset)); |
|
49873 | 50 |
Word size = WordFactory.signed(bytes); |
55674
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
51 |
|
47084 | 52 |
HotSpotBackend.unsafeArraycopy(srcAddr, dstAddr, size); |
53 |
} |
|
55674
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
54 |
|
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
55 |
@SuppressWarnings("unused") |
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
56 |
@MethodSubstitution(value = "copyMemory", isStatic = false) |
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
57 |
static void copyMemoryGuarded(Object receiver, Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes) { |
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
58 |
Word srcAddr = WordFactory.unsigned(ComputeObjectAddressNode.get(srcBase, srcOffset)); |
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
59 |
Word dstAddr = WordFactory.unsigned(ComputeObjectAddressNode.get(destBase, destOffset)); |
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
60 |
Word size = WordFactory.signed(bytes); |
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
61 |
Word javaThread = CurrentJavaThreadNode.get(); |
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
62 |
int offset = doingUnsafeAccessOffset(INJECTED_VMCONFIG); |
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
63 |
LocationIdentity any = LocationIdentity.any(); |
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
64 |
|
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
65 |
/* Set doingUnsafeAccess to guard and handle unsafe memory access failures */ |
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
66 |
javaThread.writeByte(offset, (byte) 1, any); |
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
67 |
HotSpotBackend.unsafeArraycopy(srcAddr, dstAddr, size); |
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
68 |
/* Reset doingUnsafeAccess */ |
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
69 |
javaThread.writeByte(offset, (byte) 0, any); |
ff76baab1c90
8227068: [Graal] MappedByteBuffer bulk access memory failures are not handled gracefully
jcm
parents:
55509
diff
changeset
|
70 |
} |
47084 | 71 |
} |