< prev index next >

src/hotspot/share/runtime/signature.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. 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  *


 401   }
 402 
 403   char* buffer = NEW_RESOURCE_ARRAY(char, end - begin);
 404   for (int index = begin; index < end; index++) {
 405     buffer[index - begin] = _signature->char_at(index);
 406   }
 407   Symbol* result = SymbolTable::probe(buffer, end - begin);
 408   return result;
 409 }
 410 
 411 int SignatureStream::reference_parameter_count() {
 412   int args_count = 0;
 413   for ( ; !at_return_type(); next()) {
 414     if (is_object()) {
 415       args_count++;
 416     }
 417   }
 418   return args_count;
 419 }
 420 
 421 bool SignatureVerifier::is_valid_signature(Symbol* sig) {
 422   const char* signature = (const char*)sig->bytes();
 423   ssize_t len = sig->utf8_length();
 424   if (signature == NULL || signature[0] == '\0' || len < 1) {
 425     return false;
 426   } else if (signature[0] == '(') {
 427     return is_valid_method_signature(sig);
 428   } else {
 429     return is_valid_type_signature(sig);
 430   }
 431 }
 432 
 433 bool SignatureVerifier::is_valid_method_signature(Symbol* sig) {
 434   const char* method_sig = (const char*)sig->bytes();
 435   ssize_t len = sig->utf8_length();
 436   ssize_t index = 0;
 437   if (method_sig != NULL && len > 1 && method_sig[index] == '(') {
 438     ++index;
 439     while (index < len && method_sig[index] != ')') {
 440       ssize_t res = is_valid_type(&method_sig[index], len - index);
 441       if (res == -1) {
 442         return false;
 443       } else {
 444         index += res;
 445       }
 446     }
 447     if (index < len && method_sig[index] == ')') {
 448       // check the return type
 449       ++index;
 450       return (is_valid_type(&method_sig[index], len - index) == (len - index));
 451     }
 452   }


 482           return index + 1;
 483         }
 484         if (invalid_name_char(c)) {
 485           return -1;
 486         }
 487       }
 488       // fall through
 489     default: ; // fall through
 490   }
 491   return -1;
 492 }
 493 
 494 bool SignatureVerifier::invalid_name_char(char c) {
 495   switch (c) {
 496     case '\0': case '.': case ';': case '[':
 497       return true;
 498     default:
 499       return false;
 500   }
 501 }

   1 /*
   2  * Copyright (c) 1997, 2019, Oracle and/or its affiliates. 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  *


 401   }
 402 
 403   char* buffer = NEW_RESOURCE_ARRAY(char, end - begin);
 404   for (int index = begin; index < end; index++) {
 405     buffer[index - begin] = _signature->char_at(index);
 406   }
 407   Symbol* result = SymbolTable::probe(buffer, end - begin);
 408   return result;
 409 }
 410 
 411 int SignatureStream::reference_parameter_count() {
 412   int args_count = 0;
 413   for ( ; !at_return_type(); next()) {
 414     if (is_object()) {
 415       args_count++;
 416     }
 417   }
 418   return args_count;
 419 }
 420 
 421 #ifdef ASSERT











 422 bool SignatureVerifier::is_valid_method_signature(Symbol* sig) {
 423   const char* method_sig = (const char*)sig->bytes();
 424   ssize_t len = sig->utf8_length();
 425   ssize_t index = 0;
 426   if (method_sig != NULL && len > 1 && method_sig[index] == '(') {
 427     ++index;
 428     while (index < len && method_sig[index] != ')') {
 429       ssize_t res = is_valid_type(&method_sig[index], len - index);
 430       if (res == -1) {
 431         return false;
 432       } else {
 433         index += res;
 434       }
 435     }
 436     if (index < len && method_sig[index] == ')') {
 437       // check the return type
 438       ++index;
 439       return (is_valid_type(&method_sig[index], len - index) == (len - index));
 440     }
 441   }


 471           return index + 1;
 472         }
 473         if (invalid_name_char(c)) {
 474           return -1;
 475         }
 476       }
 477       // fall through
 478     default: ; // fall through
 479   }
 480   return -1;
 481 }
 482 
 483 bool SignatureVerifier::invalid_name_char(char c) {
 484   switch (c) {
 485     case '\0': case '.': case ';': case '[':
 486       return true;
 487     default:
 488       return false;
 489   }
 490 }
 491 #endif // ASSERT
< prev index next >