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 *
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) {
|
1 /*
2 * Copyright (c) 1997, 2025, 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 *
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(bool probe_only) {
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 if (probe_only) {
487 name = SymbolTable::probe(symbol_chars, len);
488 if (name == nullptr) {
489 return nullptr;
490 }
491 } else {
492 name = SymbolTable::new_symbol(symbol_chars, len);
493 }
494 // Save names for cleaning up reference count at the end of
495 // SignatureStream scope.
496
497 // Only allocate the GrowableArray for the _names buffer if more than
498 // one name is being processed in the signature.
499 if (!_previous_name->is_permanent()) {
500 if (_names == nullptr) {
501 _names = new GrowableArray<Symbol*>(10);
502 }
503 _names->push(_previous_name);
504 }
505 _previous_name = name;
506 return name;
507 }
508
509 Klass* SignatureStream::as_klass(Handle class_loader, FailureMode failure_mode, TRAPS) {
510 if (!is_reference()) {
511 return nullptr;
512 }
513 Symbol* name = as_symbol();
514 Klass* k = nullptr;
515 if (failure_mode == ReturnNull) {
|