43972
|
1 |
/*
|
58299
|
2 |
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
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 |
|
43972
|
25 |
package org.graalvm.compiler.hotspot.replacements;
|
|
26 |
|
52956
|
27 |
import static org.graalvm.compiler.hotspot.GraalHotSpotVMConfigBase.INJECTED_INTRINSIC_CONTEXT;
|
55509
|
28 |
import static org.graalvm.compiler.hotspot.GraalHotSpotVMConfigBase.INJECTED_METAACCESS;
|
43972
|
29 |
|
|
30 |
import org.graalvm.compiler.api.replacements.ClassSubstitution;
|
52956
|
31 |
import org.graalvm.compiler.api.replacements.Fold;
|
43972
|
32 |
import org.graalvm.compiler.api.replacements.MethodSubstitution;
|
|
33 |
import org.graalvm.compiler.hotspot.HotSpotBackend;
|
52910
|
34 |
import org.graalvm.compiler.nodes.ComputeObjectAddressNode;
|
43972
|
35 |
import org.graalvm.compiler.nodes.PiNode;
|
46344
|
36 |
import org.graalvm.compiler.nodes.extended.RawLoadNode;
|
52956
|
37 |
import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext;
|
52910
|
38 |
import org.graalvm.compiler.replacements.ReplacementsUtil;
|
55509
|
39 |
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
|
43972
|
40 |
import org.graalvm.compiler.word.Word;
|
49873
|
41 |
import jdk.internal.vm.compiler.word.LocationIdentity;
|
|
42 |
import jdk.internal.vm.compiler.word.WordFactory;
|
43972
|
43 |
|
|
44 |
import jdk.vm.ci.meta.JavaKind;
|
|
45 |
|
|
46 |
@ClassSubstitution(className = "sun.security.provider.SHA2", optional = true)
|
|
47 |
public class SHA2Substitutions {
|
|
48 |
|
55509
|
49 |
public static final String implCompressName = JavaVersionUtil.JAVA_SPEC <= 8 ? "implCompress" : "implCompress0";
|
43972
|
50 |
|
|
51 |
@MethodSubstitution(isStatic = false)
|
|
52 |
static void implCompress0(Object receiver, byte[] buf, int ofs) {
|
52956
|
53 |
Object realReceiver = PiNode.piCastNonNull(receiver, HotSpotReplacementsUtil.methodHolderClass(INJECTED_INTRINSIC_CONTEXT));
|
|
54 |
Object state = RawLoadNode.load(realReceiver, stateOffset(INJECTED_INTRINSIC_CONTEXT), JavaKind.Object, LocationIdentity.any());
|
52910
|
55 |
Word bufAddr = WordFactory.unsigned(ComputeObjectAddressNode.get(buf, ReplacementsUtil.getArrayBaseOffset(INJECTED_METAACCESS, JavaKind.Byte) + ofs));
|
|
56 |
Word stateAddr = WordFactory.unsigned(ComputeObjectAddressNode.get(state, ReplacementsUtil.getArrayBaseOffset(INJECTED_METAACCESS, JavaKind.Int)));
|
43972
|
57 |
HotSpotBackend.sha2ImplCompressStub(bufAddr, stateAddr);
|
|
58 |
}
|
52956
|
59 |
|
|
60 |
@Fold
|
|
61 |
static long stateOffset(@Fold.InjectedParameter IntrinsicContext context) {
|
|
62 |
return HotSpotReplacementsUtil.getFieldOffset(HotSpotReplacementsUtil.methodHolderClass(context), "state");
|
|
63 |
}
|
43972
|
64 |
}
|