Skip to content

Commit d91550e

Browse files
committed
8262998: Vector API intrinsincs should not modify IR when bailing out
Reviewed-by: thartmann, vlivanov
1 parent 80182f9 commit d91550e

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

src/hotspot/share/opto/vectorIntrinsics.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,12 @@ bool LibraryCallKit::inline_vector_mem_operation(bool is_store) {
609609
Node* base = argument(3);
610610
Node* offset = ConvL2X(argument(4));
611611
DecoratorSet decorators = C2_UNSAFE_ACCESS;
612-
Node* addr = make_unsafe_address(base, offset, decorators, (is_mask ? T_BOOLEAN : elem_bt), true);
613612

613+
// Save state and restore on bailout
614+
uint old_sp = sp();
615+
SafePointNode* old_map = clone_map();
616+
617+
Node* addr = make_unsafe_address(base, offset, decorators, (is_mask ? T_BOOLEAN : elem_bt), true);
614618
// Can base be NULL? Otherwise, always on-heap access.
615619
bool can_access_non_heap = TypePtr::NULL_PTR->higher_equal(gvn().type(base));
616620

@@ -622,6 +626,8 @@ bool LibraryCallKit::inline_vector_mem_operation(bool is_store) {
622626
// Handle loading masks.
623627
// If there is no consistency between array and vector element types, it must be special byte array case or loading masks
624628
if (arr_type != NULL && !using_byte_array && elem_bt != arr_type->elem()->array_element_basic_type() && !is_mask) {
629+
set_map(old_map);
630+
set_sp(old_sp);
625631
return false;
626632
}
627633
// Since we are using byte array, we need to double check that the byte operations are supported by backend.
@@ -634,6 +640,8 @@ bool LibraryCallKit::inline_vector_mem_operation(bool is_store) {
634640
is_store, is_store ? "store" : "load",
635641
byte_num_elem, type2name(elem_bt));
636642
}
643+
set_map(old_map);
644+
set_sp(old_sp);
637645
return false; // not supported
638646
}
639647
}
@@ -644,14 +652,20 @@ bool LibraryCallKit::inline_vector_mem_operation(bool is_store) {
644652
is_store, is_store ? "store" : "load",
645653
num_elem);
646654
}
655+
set_map(old_map);
656+
set_sp(old_sp);
647657
return false; // not supported
648658
}
649659
if (!is_store) {
650660
if (!arch_supports_vector(Op_LoadVector, num_elem, elem_bt, VecMaskUseLoad)) {
661+
set_map(old_map);
662+
set_sp(old_sp);
651663
return false; // not supported
652664
}
653665
} else {
654666
if (!arch_supports_vector(Op_StoreVector, num_elem, elem_bt, VecMaskUseStore)) {
667+
set_map(old_map);
668+
set_sp(old_sp);
655669
return false; // not supported
656670
}
657671
}
@@ -666,6 +680,8 @@ bool LibraryCallKit::inline_vector_mem_operation(bool is_store) {
666680
if (is_store) {
667681
Node* val = unbox_vector(argument(6), vbox_type, elem_bt, num_elem);
668682
if (val == NULL) {
683+
set_map(old_map);
684+
set_sp(old_sp);
669685
return false; // operand unboxing failed
670686
}
671687
set_all_memory(reset_memory());
@@ -702,6 +718,8 @@ bool LibraryCallKit::inline_vector_mem_operation(bool is_store) {
702718
set_result(box);
703719
}
704720

721+
old_map->destruct(&_gvn);
722+
705723
if (can_access_non_heap) {
706724
insert_mem_bar(Op_MemBarCPUOrder);
707725
}
@@ -779,13 +797,20 @@ bool LibraryCallKit::inline_vector_gather_scatter(bool is_scatter) {
779797

780798
Node* base = argument(4);
781799
Node* offset = ConvL2X(argument(5));
800+
801+
// Save state and restore on bailout
802+
uint old_sp = sp();
803+
SafePointNode* old_map = clone_map();
804+
782805
Node* addr = make_unsafe_address(base, offset, C2_UNSAFE_ACCESS, elem_bt, true);
783806

784807
const TypePtr *addr_type = gvn().type(addr)->isa_ptr();
785808
const TypeAryPtr* arr_type = addr_type->isa_aryptr();
786809

787810
// The array must be consistent with vector type
788811
if (arr_type == NULL || (arr_type != NULL && elem_bt != arr_type->elem()->array_element_basic_type())) {
812+
set_map(old_map);
813+
set_sp(old_sp);
789814
return false;
790815
}
791816
ciKlass* vbox_klass = vector_klass->const_oop()->as_instance()->java_lang_Class_klass();
@@ -794,19 +819,25 @@ bool LibraryCallKit::inline_vector_gather_scatter(bool is_scatter) {
794819
ciKlass* vbox_idx_klass = vector_idx_klass->const_oop()->as_instance()->java_lang_Class_klass();
795820

796821
if (vbox_idx_klass == NULL) {
822+
set_map(old_map);
823+
set_sp(old_sp);
797824
return false;
798825
}
799826

800827
const TypeInstPtr* vbox_idx_type = TypeInstPtr::make_exact(TypePtr::NotNull, vbox_idx_klass);
801828

802829
Node* index_vect = unbox_vector(argument(7), vbox_idx_type, T_INT, num_elem);
803830
if (index_vect == NULL) {
831+
set_map(old_map);
832+
set_sp(old_sp);
804833
return false;
805834
}
806835
const TypeVect* vector_type = TypeVect::make(elem_bt, num_elem);
807836
if (is_scatter) {
808837
Node* val = unbox_vector(argument(8), vbox_type, elem_bt, num_elem);
809838
if (val == NULL) {
839+
set_map(old_map);
840+
set_sp(old_sp);
810841
return false; // operand unboxing failed
811842
}
812843
set_all_memory(reset_memory());
@@ -820,6 +851,8 @@ bool LibraryCallKit::inline_vector_gather_scatter(bool is_scatter) {
820851
set_result(box);
821852
}
822853

854+
old_map->destruct(&_gvn);
855+
823856
C->set_max_vector_size(MAX2(C->max_vector_size(), (uint)(num_elem * type2aelembytes(elem_bt))));
824857
return true;
825858
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package compiler.vectorapi;
25+
26+
import jdk.incubator.vector.*;
27+
import java.nio.ByteOrder;
28+
29+
/*
30+
* @test
31+
* @bug 8262998
32+
* @summary Vector API intrinsincs should not modify IR when bailing out
33+
* @modules jdk.incubator.vector
34+
* @run main/othervm -Xbatch -XX:+IgnoreUnrecognizedVMOptions -XX:UseAVX=1
35+
* -XX:-TieredCompilation compiler.vectorapi.TestIntrinsicBailOut
36+
*/
37+
38+
39+
public class TestIntrinsicBailOut {
40+
static final VectorSpecies<Double> SPECIES256 = DoubleVector.SPECIES_256;
41+
static byte[] a = new byte[512];
42+
static byte[] r = new byte[512];
43+
44+
static void test() {
45+
DoubleVector av = DoubleVector.fromByteArray(SPECIES256, a, 0, ByteOrder.BIG_ENDIAN);
46+
av.intoByteArray(r, 0, ByteOrder.BIG_ENDIAN);
47+
48+
DoubleVector bv = DoubleVector.fromByteArray(SPECIES256, a, 32, ByteOrder.LITTLE_ENDIAN);
49+
bv.intoByteArray(r, 32, ByteOrder.LITTLE_ENDIAN);
50+
}
51+
52+
public static void main(String[] args) {
53+
for (int i = 0; i < 15000; i++) {
54+
test();
55+
}
56+
System.out.println(r[0] + r[32]);
57+
}
58+
}

0 commit comments

Comments
 (0)