@@ -939,7 +939,11 @@ inline Node* LibraryCallKit::generate_limit_guard(Node* offset,
939939}
940940
941941// Emit range checks for the given String.value byte array
942- void LibraryCallKit::generate_string_range_check (Node* array, Node* offset, Node* count, bool char_count) {
942+ void LibraryCallKit::generate_string_range_check (Node* array,
943+ Node* offset,
944+ Node* count,
945+ bool char_count,
946+ bool halt_on_oob) {
943947 if (stopped ()) {
944948 return ; // already stopped
945949 }
@@ -957,10 +961,17 @@ void LibraryCallKit::generate_string_range_check(Node* array, Node* offset, Node
957961 generate_limit_guard (offset, count, load_array_length (array), bailout);
958962
959963 if (bailout->req () > 1 ) {
960- PreserveJVMState pjvms (this );
961- set_control (_gvn.transform (bailout));
962- uncommon_trap (Deoptimization::Reason_intrinsic,
963- Deoptimization::Action_maybe_recompile);
964+ if (halt_on_oob) {
965+ bailout = _gvn.transform (bailout)->as_Region ();
966+ Node* frame = _gvn.transform (new ParmNode (C->start (), TypeFunc::FramePtr));
967+ Node* halt = _gvn.transform (new HaltNode (bailout, frame, " unexpected guard failure in intrinsic" ));
968+ C->root ()->add_req (halt);
969+ } else {
970+ PreserveJVMState pjvms (this );
971+ set_control (_gvn.transform (bailout));
972+ uncommon_trap (Deoptimization::Reason_intrinsic,
973+ Deoptimization::Action_maybe_recompile);
974+ }
964975 }
965976}
966977
@@ -1118,6 +1129,7 @@ bool LibraryCallKit::inline_array_equals(StrIntrinsicNode::ArgEnc ae) {
11181129
11191130
11201131// ------------------------------inline_countPositives------------------------------
1132+ // int java.lang.StringCoding#countPositives0(byte[] ba, int off, int len)
11211133bool LibraryCallKit::inline_countPositives () {
11221134 if (too_many_traps (Deoptimization::Reason_intrinsic)) {
11231135 return false ;
@@ -1129,13 +1141,14 @@ bool LibraryCallKit::inline_countPositives() {
11291141 Node* offset = argument (1 );
11301142 Node* len = argument (2 );
11311143
1132- ba = must_be_not_null (ba, true );
1133-
1134- // Range checks
1135- generate_string_range_check (ba, offset, len, false );
1136- if ( stopped ()) {
1137- return true ;
1144+ if (VerifyIntrinsicChecks) {
1145+ ba = must_be_not_null (ba, true );
1146+ generate_string_range_check (ba, offset, len, false , true );
1147+ if ( stopped ()) {
1148+ return true ;
1149+ }
11381150 }
1151+
11391152 Node* ba_start = array_element_address (ba, offset, T_BYTE);
11401153 Node* result = new CountPositivesNode (control (), memory (TypeAryPtr::BYTES), ba_start, len);
11411154 set_result (_gvn.transform (result));
@@ -6128,6 +6141,9 @@ CallStaticJavaNode* LibraryCallKit::get_uncommon_trap_from_success_proj(Node* no
61286141}
61296142
61306143// -------------inline_encodeISOArray-----------------------------------
6144+ // int sun.nio.cs.ISO_8859_1.Encoder#encodeISOArray0(byte[] sa, int sp, byte[] da, int dp, int len)
6145+ // int java.lang.StringCoding#encodeISOArray0(byte[] sa, int sp, byte[] da, int dp, int len)
6146+ // int java.lang.StringCoding#encodeAsciiArray0(char[] sa, int sp, byte[] da, int dp, int len)
61316147// encode char[] to byte[] in ISO_8859_1 or ASCII
61326148bool LibraryCallKit::inline_encodeISOArray (bool ascii) {
61336149 assert (callee ()->signature ()->size () == 5 , " encodeISOArray has 5 parameters" );
@@ -6138,8 +6154,14 @@ bool LibraryCallKit::inline_encodeISOArray(bool ascii) {
61386154 Node *dst_offset = argument (3 );
61396155 Node *length = argument (4 );
61406156
6141- src = must_be_not_null (src, true );
6142- dst = must_be_not_null (dst, true );
6157+ // Cast source & target arrays to not-null
6158+ if (VerifyIntrinsicChecks) {
6159+ src = must_be_not_null (src, true );
6160+ dst = must_be_not_null (dst, true );
6161+ if (stopped ()) {
6162+ return true ;
6163+ }
6164+ }
61436165
61446166 const TypeAryPtr* src_type = src->Value (&_gvn)->isa_aryptr ();
61456167 const TypeAryPtr* dst_type = dst->Value (&_gvn)->isa_aryptr ();
@@ -6156,6 +6178,15 @@ bool LibraryCallKit::inline_encodeISOArray(bool ascii) {
61566178 return false ;
61576179 }
61586180
6181+ // Check source & target bounds
6182+ if (VerifyIntrinsicChecks) {
6183+ generate_string_range_check (src, src_offset, length, src_elem == T_BYTE, true );
6184+ generate_string_range_check (dst, dst_offset, length, false , true );
6185+ if (stopped ()) {
6186+ return true ;
6187+ }
6188+ }
6189+
61596190 Node* src_start = array_element_address (src, src_offset, T_CHAR);
61606191 Node* dst_start = array_element_address (dst, dst_offset, dst_elem);
61616192 // 'src_start' points to src array + scaled offset
0 commit comments