1 /* 2 * Copyright (c) 1997, 2024, 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 * 23 */ 24 25 #include "asm/assembler.hpp" 26 #include "classfile/symbolTable.hpp" 27 #include "classfile/systemDictionary.hpp" 28 #include "classfile/vmSymbols.hpp" 29 #include "memory/oopFactory.hpp" 30 #include "memory/resourceArea.hpp" 31 #include "memory/universe.hpp" 32 #include "oops/instanceKlass.hpp" 33 #include "oops/klass.inline.hpp" 34 #include "oops/oop.inline.hpp" 35 #include "oops/symbol.hpp" 36 #include "oops/typeArrayKlass.hpp" 37 #include "runtime/fieldDescriptor.inline.hpp" 38 #include "runtime/handles.inline.hpp" 39 #include "runtime/safepointVerifiers.hpp" 40 #include "runtime/sharedRuntime.hpp" 41 #include "runtime/signature.hpp" 42 43 // Implementation of SignatureIterator 44 45 // Signature syntax: 46 // 47 // Signature = "(" {Parameter} ")" ReturnType. 48 // Parameter = FieldType. 49 // ReturnType = FieldType | "V". 50 // FieldType = "B" | "C" | "D" | "F" | "I" | "J" | "S" | "Z" | "L" ClassName ";" | "[" FieldType. 51 // ClassName = string. 52 53 // The ClassName string can be any JVM-style UTF8 string except: 54 // - an empty string (the empty string is never a name of any kind) 55 // - a string which begins or ends with slash '/' (the package separator) 56 // - a string which contains adjacent slashes '//' (no empty package names) 57 // - a string which contains a semicolon ';' (the end-delimiter) 58 // - a string which contains a left bracket '[' (the array marker) 59 // - a string which contains a dot '.' (the external package separator) 60 // 61 // Other "meta-looking" characters, such as '(' and '<' and '+', 62 // are perfectly legitimate within a class name, for the JVM. 63 // Class names which contain double slashes ('a//b') and non-initial 64 // brackets ('a[b]') are reserved for possible enrichment of the 65 // type language. 66 67 void SignatureIterator::set_fingerprint(fingerprint_t fingerprint) { 68 if (!fp_is_valid(fingerprint)) { 69 _fingerprint = fingerprint; 70 _return_type = T_ILLEGAL; 71 } else if (fingerprint != _fingerprint) { 72 assert(_fingerprint == zero_fingerprint(), "consistent fingerprint values"); 73 _fingerprint = fingerprint; 74 _return_type = fp_return_type(fingerprint); 75 } 76 } 77 78 BasicType SignatureIterator::return_type() { 79 if (_return_type == T_ILLEGAL) { 80 SignatureStream ss(_signature); 81 ss.skip_to_return_type(); 82 _return_type = ss.type(); 83 assert(_return_type != T_ILLEGAL, "illegal return type"); 84 } 85 return _return_type; 86 } 87 88 bool SignatureIterator::fp_is_valid_type(BasicType type, bool for_return_type) { 89 assert(type != (BasicType)fp_parameters_done, "fingerprint is incorrectly at done"); 90 assert(((int)type & ~fp_parameter_feature_mask) == 0, "fingerprint feature mask yielded non-zero value"); 91 return (is_java_primitive(type) || 92 is_reference_type(type) || 93 (for_return_type && type == T_VOID)); 94 } 95 96 ArgumentSizeComputer::ArgumentSizeComputer(Symbol* signature) 97 : SignatureIterator(signature) 98 { 99 _size = 0; 100 do_parameters_on(this); // non-virtual template execution 101 } 102 103 ArgumentCount::ArgumentCount(Symbol* signature) 104 : SignatureIterator(signature) 105 { 106 _size = 0; 107 do_parameters_on(this); // non-virtual template execution 108 } 109 110 ReferenceArgumentCount::ReferenceArgumentCount(Symbol* signature) 111 : SignatureIterator(signature) 112 { 113 _refs = 0; 114 do_parameters_on(this); // non-virtual template execution 115 } 116 117 #if !defined(_LP64) || defined(ZERO) || defined(ASSERT) 118 static int compute_num_stack_arg_slots(Symbol* signature, int sizeargs, bool is_static) { 119 ResourceMark rm; 120 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs); 121 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs); 122 123 int sig_index = 0; 124 if (!is_static) { 125 sig_bt[sig_index++] = T_OBJECT; // 'this' 126 } 127 for (SignatureStream ss(signature); !ss.at_return_type(); ss.next()) { 128 BasicType t = ss.type(); 129 assert(type2size[t] == 1 || type2size[t] == 2, "size is 1 or 2"); 130 sig_bt[sig_index++] = t; 131 if (type2size[t] == 2) { 132 sig_bt[sig_index++] = T_VOID; 133 } 134 } 135 assert(sig_index == sizeargs, "sig_index: %d sizeargs: %d", sig_index, sizeargs); 136 137 return SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs); 138 } 139 #endif 140 141 void Fingerprinter::compute_fingerprint_and_return_type(bool static_flag) { 142 // See if we fingerprinted this method already 143 if (_method != nullptr) { 144 assert(!static_flag, "must not be passed by caller"); 145 static_flag = _method->is_static(); 146 _fingerprint = _method->constMethod()->fingerprint(); 147 148 if (_fingerprint != zero_fingerprint()) { 149 _return_type = _method->result_type(); 150 assert(is_java_type(_return_type), "return type must be a java type"); 151 return; 152 } 153 154 if (_method->size_of_parameters() > fp_max_size_of_parameters) { 155 _fingerprint = overflow_fingerprint(); 156 _method->constMethod()->set_fingerprint(_fingerprint); 157 // as long as we are here compute the return type: 158 _return_type = ResultTypeFinder(_method->signature()).type(); 159 assert(is_java_type(_return_type), "return type must be a java type"); 160 return; 161 } 162 } 163 164 // Note: This will always take the slow path, since _fp==zero_fp. 165 initialize_accumulator(); 166 initialize_calling_convention(static_flag); 167 do_parameters_on(this); 168 assert(fp_is_valid_type(_return_type, true), "bad result type"); 169 170 // Fill in the return type and static bits: 171 _accumulator |= _return_type << fp_static_feature_size; 172 if (static_flag) { 173 _accumulator |= fp_is_static_bit; 174 } else { 175 _param_size += 1; // this is the convention for Method::compute_size_of_parameters 176 } 177 178 #if defined(_LP64) && !defined(ZERO) 179 #ifdef ASSERT 180 int dbg_stack_arg_slots = compute_num_stack_arg_slots(_signature, _param_size, static_flag); 181 assert(_stack_arg_slots == dbg_stack_arg_slots, "fingerprinter: %d full: %d", _stack_arg_slots, dbg_stack_arg_slots); 182 #endif 183 #else 184 // Fallback: computed _stack_arg_slots is unreliable, compute directly. 185 _stack_arg_slots = compute_num_stack_arg_slots(_signature, _param_size, static_flag); 186 #endif 187 188 // Detect overflow. (We counted _param_size correctly.) 189 if (_method == nullptr && _param_size > fp_max_size_of_parameters) { 190 // We did a one-pass computation of argument size, return type, 191 // and fingerprint. 192 _fingerprint = overflow_fingerprint(); 193 return; 194 } 195 196 assert(_shift_count < BitsPerLong, 197 "shift count overflow %d (%d vs. %d): %s", 198 _shift_count, _param_size, fp_max_size_of_parameters, 199 _signature->as_C_string()); 200 assert((_accumulator >> _shift_count) == fp_parameters_done, "must be zero"); 201 202 // This is the result, along with _return_type: 203 _fingerprint = _accumulator; 204 205 // Cache the result on the method itself: 206 if (_method != nullptr) { 207 _method->constMethod()->set_fingerprint(_fingerprint); 208 } 209 } 210 211 void Fingerprinter::initialize_calling_convention(bool static_flag) { 212 _int_args = 0; 213 _fp_args = 0; 214 215 if (!static_flag) { // `this` takes up an int register 216 _int_args++; 217 } 218 } 219 220 void Fingerprinter::do_type_calling_convention(BasicType type) { 221 // We compute the number of slots for stack-passed arguments in compiled calls. 222 // TODO: SharedRuntime::java_calling_convention is the shared code that knows all details 223 // about the platform-specific calling conventions. This method tries to compute the stack 224 // args number... poorly, at least for 32-bit ports and for zero. Current code has the fallback 225 // that recomputes the stack args number from SharedRuntime::java_calling_convention. 226 #if defined(_LP64) && !defined(ZERO) 227 switch (type) { 228 case T_VOID: 229 break; 230 case T_BOOLEAN: 231 case T_CHAR: 232 case T_BYTE: 233 case T_SHORT: 234 case T_INT: 235 if (_int_args < Argument::n_int_register_parameters_j) { 236 _int_args++; 237 } else { 238 #if defined(PPC64) || defined(S390) 239 _stack_arg_slots += 1; 240 #else 241 _stack_arg_slots = align_up(_stack_arg_slots, 2); 242 _stack_arg_slots += 1; 243 #endif // defined(PPC64) || defined(S390) 244 } 245 break; 246 case T_LONG: 247 case T_OBJECT: 248 case T_ARRAY: 249 case T_ADDRESS: 250 if (_int_args < Argument::n_int_register_parameters_j) { 251 _int_args++; 252 } else { 253 _stack_arg_slots = align_up(_stack_arg_slots, 2); 254 _stack_arg_slots += 2; 255 } 256 break; 257 case T_FLOAT: 258 if (_fp_args < Argument::n_float_register_parameters_j) { 259 _fp_args++; 260 } else { 261 #if defined(PPC64) || defined(S390) 262 _stack_arg_slots += 1; 263 #else 264 _stack_arg_slots = align_up(_stack_arg_slots, 2); 265 _stack_arg_slots += 1; 266 #endif // defined(PPC64) || defined(S390) 267 } 268 break; 269 case T_DOUBLE: 270 if (_fp_args < Argument::n_float_register_parameters_j) { 271 _fp_args++; 272 } else { 273 _stack_arg_slots = align_up(_stack_arg_slots, 2); 274 _stack_arg_slots += 2; 275 } 276 break; 277 default: 278 ShouldNotReachHere(); 279 break; 280 } 281 #endif 282 } 283 284 // Implementation of SignatureStream 285 286 static inline BasicType decode_signature_char(int ch) { 287 switch (ch) { 288 #define EACH_SIG(ch, bt, ignore) \ 289 case ch: return bt; 290 SIGNATURE_TYPES_DO(EACH_SIG, ignore) 291 #undef EACH_SIG 292 } 293 return (BasicType)0; 294 } 295 296 SignatureStream::SignatureStream(const Symbol* signature, 297 bool is_method) { 298 assert(!is_method || signature->starts_with(JVM_SIGNATURE_FUNC), 299 "method signature required"); 300 _signature = signature; 301 _limit = signature->utf8_length(); 302 int oz = (is_method ? _s_method : _s_field); 303 _state = oz; 304 _begin = _end = oz; // skip first '(' in method signatures 305 _array_prefix = 0; // just for definiteness 306 307 // assigning java/lang/Object to _previous_name means we can 308 // avoid a number of null checks in the parser 309 _previous_name = vmSymbols::java_lang_Object(); 310 _names = nullptr; 311 next(); 312 } 313 314 SignatureStream::~SignatureStream() { 315 if (_previous_name == vmSymbols::java_lang_Object()) { 316 // no names were created 317 assert(_names == nullptr, "_names unexpectedly created"); 318 return; 319 } 320 321 // decrement refcount for names created during signature parsing 322 _previous_name->decrement_refcount(); 323 if (_names != nullptr) { 324 for (int i = 0; i < _names->length(); i++) { 325 _names->at(i)->decrement_refcount(); 326 } 327 } 328 } 329 330 inline int SignatureStream::scan_type(BasicType type) { 331 const u1* base = _signature->bytes(); 332 int end = _end; 333 int limit = _limit; 334 const u1* tem; 335 switch (type) { 336 case T_OBJECT: 337 tem = (const u1*) memchr(&base[end], JVM_SIGNATURE_ENDCLASS, limit - end); 338 return (tem == nullptr ? limit : pointer_delta_as_int(tem + 1, base)); 339 340 case T_ARRAY: 341 while ((end < limit) && ((char)base[end] == JVM_SIGNATURE_ARRAY)) { end++; } 342 // If we discovered only the string of '[', this means something is wrong. 343 if (end >= limit) { 344 assert(false, "Invalid type detected"); 345 return limit; 346 } 347 _array_prefix = end - _end; // number of '[' chars just skipped 348 if (Signature::has_envelope(base[end])) { 349 tem = (const u1 *) memchr(&base[end], JVM_SIGNATURE_ENDCLASS, limit - end); 350 return (tem == nullptr ? limit : pointer_delta_as_int(tem + 1, base)); 351 } 352 // Skipping over a single character for a primitive type. 353 assert(is_java_primitive(decode_signature_char(base[end])), "only primitives expected"); 354 return end + 1; 355 356 default: 357 // Skipping over a single character for a primitive type (or void). 358 assert(!is_reference_type(type), "only primitives or void expected"); 359 return end + 1; 360 } 361 } 362 363 void SignatureStream::next() { 364 const Symbol* sig = _signature; 365 int len = _limit; 366 if (_end >= len) { set_done(); return; } 367 _begin = _end; 368 int ch = sig->char_at(_begin); 369 if (ch == JVM_SIGNATURE_ENDFUNC) { 370 assert(_state == _s_method, "must be in method"); 371 _state = _s_method_return; 372 _begin = ++_end; 373 if (_end >= len) { set_done(); return; } 374 ch = sig->char_at(_begin); 375 } 376 BasicType bt = decode_signature_char(ch); 377 assert(ch == type2char(bt), "bad signature char %c/%d", ch, ch); 378 _type = bt; 379 _end = scan_type(bt); 380 } 381 382 int SignatureStream::skip_whole_array_prefix() { 383 assert(_type == T_ARRAY, "must be"); 384 385 // we are stripping all levels of T_ARRAY, 386 // so we must decode the next character 387 int whole_array_prefix = _array_prefix; 388 int new_begin = _begin + whole_array_prefix; 389 _begin = new_begin; 390 int ch = _signature->char_at(new_begin); 391 BasicType bt = decode_signature_char(ch); 392 assert(ch == type2char(bt), "bad signature char %c/%d", ch, ch); 393 _type = bt; 394 assert(bt != T_VOID && bt != T_ARRAY, "bad signature type"); 395 // Don't bother to re-scan, since it won't change the value of _end. 396 return whole_array_prefix; 397 } 398 399 bool Signature::is_valid_array_signature(const Symbol* sig) { 400 assert(sig->utf8_length() > 1, "this should already have been checked"); 401 assert(sig->char_at(0) == JVM_SIGNATURE_ARRAY, "this should already have been checked"); 402 // The first character is already checked 403 int i = 1; 404 int len = sig->utf8_length(); 405 // First skip all '['s 406 while(i < len - 1 && sig->char_at(i) == JVM_SIGNATURE_ARRAY) i++; 407 408 // Check type 409 switch(sig->char_at(i)) { 410 case JVM_SIGNATURE_BYTE: 411 case JVM_SIGNATURE_CHAR: 412 case JVM_SIGNATURE_DOUBLE: 413 case JVM_SIGNATURE_FLOAT: 414 case JVM_SIGNATURE_INT: 415 case JVM_SIGNATURE_LONG: 416 case JVM_SIGNATURE_SHORT: 417 case JVM_SIGNATURE_BOOLEAN: 418 // If it is an array, the type is the last character 419 return (i + 1 == len); 420 case JVM_SIGNATURE_CLASS: 421 // If it is an object, the last character must be a ';' 422 return sig->char_at(len - 1) == JVM_SIGNATURE_ENDCLASS; 423 } 424 return false; 425 } 426 427 BasicType Signature::basic_type(int ch) { 428 BasicType btcode = decode_signature_char(ch); 429 if (btcode == 0) return T_ILLEGAL; 430 return btcode; 431 } 432 433 Symbol* Signature::strip_envelope(const Symbol* signature) { 434 assert(has_envelope(signature), "precondition"); 435 return SymbolTable::new_symbol((char*) signature->bytes() + 1, 436 signature->utf8_length() - 2); 437 } 438 439 static const int jl_len = 10, object_len = 6, jl_object_len = jl_len + object_len; 440 static const char jl_str[] = "java/lang/"; 441 442 #ifdef ASSERT 443 static bool signature_symbols_sane() { 444 static bool done; 445 if (done) return true; 446 done = true; 447 // test some tense code that looks for common symbol names: 448 assert(vmSymbols::java_lang_Object()->utf8_length() == jl_object_len && 449 vmSymbols::java_lang_Object()->starts_with(jl_str, jl_len) && 450 vmSymbols::java_lang_Object()->ends_with("Object", object_len) && 451 vmSymbols::java_lang_Object()->is_permanent() && 452 vmSymbols::java_lang_String()->utf8_length() == jl_object_len && 453 vmSymbols::java_lang_String()->starts_with(jl_str, jl_len) && 454 vmSymbols::java_lang_String()->ends_with("String", object_len) && 455 vmSymbols::java_lang_String()->is_permanent(), 456 "sanity"); 457 return true; 458 } 459 #endif //ASSERT 460 461 // returns a symbol; the caller is responsible for decrementing it 462 Symbol* SignatureStream::find_symbol() { 463 // Create a symbol from for string _begin _end 464 int begin = raw_symbol_begin(); 465 int end = raw_symbol_end(); 466 467 const char* symbol_chars = (const char*)_signature->base() + begin; 468 int len = end - begin; 469 470 // Quick check for common symbols in signatures 471 assert(signature_symbols_sane(), "incorrect signature sanity check"); 472 if (len == jl_object_len && 473 memcmp(symbol_chars, jl_str, jl_len) == 0) { 474 if (memcmp("String", symbol_chars + jl_len, object_len) == 0) { 475 return vmSymbols::java_lang_String(); 476 } else if (memcmp("Object", symbol_chars + jl_len, object_len) == 0) { 477 return vmSymbols::java_lang_Object(); 478 } 479 } 480 481 Symbol* name = _previous_name; 482 if (name->equals(symbol_chars, len)) { 483 return name; 484 } 485 486 // Save names for cleaning up reference count at the end of 487 // SignatureStream scope. 488 name = SymbolTable::new_symbol(symbol_chars, len); 489 490 // Only allocate the GrowableArray for the _names buffer if more than 491 // one name is being processed in the signature. 492 if (!_previous_name->is_permanent()) { 493 if (_names == nullptr) { 494 _names = new GrowableArray<Symbol*>(10); 495 } 496 _names->push(_previous_name); 497 } 498 _previous_name = name; 499 return name; 500 } 501 502 Klass* SignatureStream::as_klass(Handle class_loader, FailureMode failure_mode, TRAPS) { 503 if (!is_reference()) { 504 return nullptr; 505 } 506 Symbol* name = as_symbol(); 507 Klass* k = nullptr; 508 if (failure_mode == ReturnNull) { 509 // Note: SD::resolve_or_null returns null for most failure modes, 510 // but not all. Circularity errors, invalid PDs, etc., throw. 511 k = SystemDictionary::resolve_or_null(name, class_loader, CHECK_NULL); 512 } else if (failure_mode == CachedOrNull) { 513 NoSafepointVerifier nsv; // no loading, now, we mean it! 514 assert(!HAS_PENDING_EXCEPTION, ""); 515 k = SystemDictionary::find_instance_klass(THREAD, name, class_loader); 516 // SD::find does not trigger loading, so there should be no throws 517 // Still, bad things can happen, so we CHECK_NULL and ask callers 518 // to do likewise. 519 return k; 520 } else { 521 // The only remaining failure mode is NCDFError. 522 // The test here allows for an additional mode CNFException 523 // if callers need to request the reflective error instead. 524 bool throw_error = (failure_mode == NCDFError); 525 k = SystemDictionary::resolve_or_fail(name, class_loader, throw_error, CHECK_NULL); 526 } 527 528 return k; 529 } 530 531 oop SignatureStream::as_java_mirror(Handle class_loader, FailureMode failure_mode, TRAPS) { 532 if (!is_reference()) { 533 return Universe::java_mirror(type()); 534 } 535 Klass* klass = as_klass(class_loader, failure_mode, CHECK_NULL); 536 if (klass == nullptr) { 537 return nullptr; 538 } 539 return klass->java_mirror(); 540 } 541 542 void SignatureStream::skip_to_return_type() { 543 while (!at_return_type()) { 544 next(); 545 } 546 } 547 548 ResolvingSignatureStream::ResolvingSignatureStream(Symbol* signature, 549 Handle class_loader, 550 bool is_method) 551 : SignatureStream(signature, is_method), _class_loader(class_loader) 552 { 553 initialize_load_origin(nullptr); 554 } 555 556 ResolvingSignatureStream::ResolvingSignatureStream(Symbol* signature, Klass* load_origin, bool is_method) 557 : SignatureStream(signature, is_method) 558 { 559 assert(load_origin != nullptr, ""); 560 initialize_load_origin(load_origin); 561 } 562 563 ResolvingSignatureStream::ResolvingSignatureStream(const Method* method) 564 : SignatureStream(method->signature(), true) 565 { 566 initialize_load_origin(method->method_holder()); 567 } 568 569 void ResolvingSignatureStream::cache_handles() { 570 assert(_load_origin != nullptr, ""); 571 JavaThread* current = JavaThread::current(); 572 _class_loader = Handle(current, _load_origin->class_loader()); 573 } 574 575 #ifdef ASSERT 576 577 extern bool signature_constants_sane(); // called from basic_types_init() 578 579 bool signature_constants_sane() { 580 // for the lookup table, test every 8-bit code point, and then some: 581 for (int i = -256; i <= 256; i++) { 582 int btcode = 0; 583 switch (i) { 584 #define EACH_SIG(ch, bt, ignore) \ 585 case ch: { btcode = bt; break; } 586 SIGNATURE_TYPES_DO(EACH_SIG, ignore) 587 #undef EACH_SIG 588 } 589 int btc = decode_signature_char(i); 590 assert(btc == btcode, "misconfigured table: %d => %d not %d", i, btc, btcode); 591 } 592 return true; 593 } 594 595 bool SignatureVerifier::is_valid_method_signature(Symbol* sig) { 596 const char* method_sig = (const char*)sig->bytes(); 597 ssize_t len = sig->utf8_length(); 598 ssize_t index = 0; 599 if (method_sig != nullptr && len > 1 && method_sig[index] == JVM_SIGNATURE_FUNC) { 600 ++index; 601 while (index < len && method_sig[index] != JVM_SIGNATURE_ENDFUNC) { 602 ssize_t res = is_valid_type(&method_sig[index], len - index); 603 if (res == -1) { 604 return false; 605 } else { 606 index += res; 607 } 608 } 609 if (index < len && method_sig[index] == JVM_SIGNATURE_ENDFUNC) { 610 // check the return type 611 ++index; 612 return (is_valid_type(&method_sig[index], len - index) == (len - index)); 613 } 614 } 615 return false; 616 } 617 618 bool SignatureVerifier::is_valid_type_signature(Symbol* sig) { 619 const char* type_sig = (const char*)sig->bytes(); 620 ssize_t len = sig->utf8_length(); 621 return (type_sig != nullptr && len >= 1 && 622 (is_valid_type(type_sig, len) == len)); 623 } 624 625 // Checks to see if the type (not to go beyond 'limit') refers to a valid type. 626 // Returns -1 if it is not, or the index of the next character that is not part 627 // of the type. The type encoding may end before 'limit' and that's ok. 628 ssize_t SignatureVerifier::is_valid_type(const char* type, ssize_t limit) { 629 ssize_t index = 0; 630 631 // Iterate over any number of array dimensions 632 while (index < limit && type[index] == JVM_SIGNATURE_ARRAY) ++index; 633 if (index >= limit) { 634 return -1; 635 } 636 switch (type[index]) { 637 case JVM_SIGNATURE_BYTE: 638 case JVM_SIGNATURE_CHAR: 639 case JVM_SIGNATURE_FLOAT: 640 case JVM_SIGNATURE_DOUBLE: 641 case JVM_SIGNATURE_INT: 642 case JVM_SIGNATURE_LONG: 643 case JVM_SIGNATURE_SHORT: 644 case JVM_SIGNATURE_BOOLEAN: 645 case JVM_SIGNATURE_VOID: 646 return index + 1; 647 case JVM_SIGNATURE_CLASS: 648 for (index = index + 1; index < limit; ++index) { 649 char c = type[index]; 650 switch (c) { 651 case JVM_SIGNATURE_ENDCLASS: 652 return index + 1; 653 case '\0': case JVM_SIGNATURE_DOT: case JVM_SIGNATURE_ARRAY: 654 return -1; 655 default: ; // fall through 656 } 657 } 658 // fall through 659 default: ; // fall through 660 } 661 return -1; 662 } 663 664 #endif // ASSERT