< prev index next >

src/hotspot/share/cds/classListParser.cpp

Print this page

   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 "precompiled.hpp"
  26 #include "cds/archiveUtils.hpp"

  27 #include "cds/classListParser.hpp"

  28 #include "cds/lambdaFormInvokers.hpp"
  29 #include "cds/metaspaceShared.hpp"
  30 #include "cds/unregisteredClasses.hpp"
  31 #include "classfile/classLoaderExt.hpp"
  32 #include "classfile/javaClasses.inline.hpp"
  33 #include "classfile/symbolTable.hpp"
  34 #include "classfile/systemDictionary.hpp"
  35 #include "classfile/systemDictionaryShared.hpp"
  36 #include "classfile/vmClasses.hpp"
  37 #include "classfile/vmSymbols.hpp"
  38 #include "interpreter/bytecode.hpp"
  39 #include "interpreter/bytecodeStream.hpp"
  40 #include "interpreter/linkResolver.hpp"
  41 #include "jimage.hpp"
  42 #include "jvm.h"
  43 #include "logging/log.hpp"
  44 #include "logging/logTag.hpp"

  45 #include "memory/resourceArea.hpp"
  46 #include "oops/constantPool.inline.hpp"

  47 #include "runtime/atomic.hpp"
  48 #include "runtime/handles.inline.hpp"
  49 #include "runtime/java.hpp"
  50 #include "runtime/javaCalls.hpp"
  51 #include "utilities/defaultStream.hpp"
  52 #include "utilities/macros.hpp"
  53 







  54 volatile Thread* ClassListParser::_parsing_thread = nullptr;
  55 ClassListParser* ClassListParser::_instance = nullptr;
  56 
  57 ClassListParser::ClassListParser(const char* file, ParseMode parse_mode) : _id2klass_table(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE) {
  58   log_info(cds)("Parsing %s%s", file,
  59                 (parse_mode == _parse_lambda_forms_invokers_only) ? " (lambda form invokers only)" : "");
  60   _classlist_file = file;
  61   _file = nullptr;
  62   // Use os::open() because neither fopen() nor os::fopen()
  63   // can handle long path name on Windows.
  64   int fd = os::open(file, O_RDONLY, S_IREAD);
  65   if (fd != -1) {
  66     // Obtain a File* from the file descriptor so that fgets()
  67     // can be used in parse_one_line()
  68     _file = os::fdopen(fd, "r");
  69   }
  70   if (_file == nullptr) {
  71     char errmsg[JVM_MAXPATHLEN];
  72     os::lasterror(errmsg, JVM_MAXPATHLEN);
  73     vm_exit_during_initialization("Loading classlist failed", errmsg);

  90 
  91 ClassListParser::~ClassListParser() {
  92   if (_file != nullptr) {
  93     fclose(_file);
  94   }
  95   Atomic::store(&_parsing_thread, (Thread*)nullptr);
  96   delete _indy_items;
  97   delete _interfaces;
  98   _instance = nullptr;
  99 }
 100 
 101 int ClassListParser::parse(TRAPS) {
 102   int class_count = 0;
 103 
 104   while (parse_one_line()) {
 105     if (lambda_form_line()) {
 106       // The current line is "@lambda-form-invoker ...". It has been recorded in LambdaFormInvokers,
 107       // and will be processed later.
 108       continue;
 109     }
 110 








 111     if (_parse_mode == _parse_lambda_forms_invokers_only) {
 112       continue;
 113     }
 114 
 115     TempNewSymbol class_name_symbol = SymbolTable::new_symbol(_class_name);
 116     if (_indy_items->length() > 0) {
 117       // The current line is "@lambda-proxy class_name". Load the proxy class.
 118       resolve_indy(THREAD, class_name_symbol);
 119       class_count++;
 120       continue;
 121     }
 122 
 123     Klass* klass = load_current_class(class_name_symbol, THREAD);
 124     if (HAS_PENDING_EXCEPTION) {
 125       if (PENDING_EXCEPTION->is_a(vmClasses::OutOfMemoryError_klass())) {
 126         // If we have run out of memory, don't try to load the rest of the classes in
 127         // the classlist. Throw an exception, which will terminate the dumping process.
 128         return 0; // THROW
 129       }
 130 

 195           len --;
 196         } else {
 197           break;
 198         }
 199       }
 200       _line_len = len;
 201     }
 202 
 203     // valid line
 204     break;
 205   }
 206 
 207   _class_name = _line;
 208   _id = _unspecified;
 209   _super = _unspecified;
 210   _interfaces->clear();
 211   _source = nullptr;
 212   _interfaces_specified = false;
 213   _indy_items->clear();
 214   _lambda_form_line = false;



 215 
 216   if (_line[0] == '@') {
 217     return parse_at_tags();
 218   }
 219 
 220   if ((_token = strchr(_line, ' ')) == nullptr) {
 221     // No optional arguments are specified.
 222     return true;
 223   }
 224 
 225   // Mark the end of the name, and go to the next input char
 226   *_token++ = '\0';
 227 
 228   while (*_token) {
 229     skip_whitespaces();
 230 
 231     if (parse_uint_option("id:", &_id)) {
 232       continue;
 233     } else if (parse_uint_option("super:", &_super)) {
 234       check_already_loaded("Super class", _super);

 297 bool ClassListParser::parse_at_tags() {
 298   assert(_line[0] == '@', "must be");
 299   int offset;
 300   if ((offset = split_at_tag_from_line()) == 0) {
 301     return false;
 302   }
 303 
 304   if (strcmp(_token, LAMBDA_PROXY_TAG) == 0) {
 305     split_tokens_by_whitespace(offset);
 306     if (_indy_items->length() < 2) {
 307       error("Line with @ tag has too few items \"%s\" line #%d", _token, _line_no);
 308       return false;
 309     }
 310     // set the class name
 311     _class_name = _indy_items->at(0);
 312     return true;
 313   } else if (strcmp(_token, LAMBDA_FORM_TAG) == 0) {
 314     LambdaFormInvokers::append(os::strdup((const char*)(_line + offset), mtInternal));
 315     _lambda_form_line = true;
 316     return true;




















 317   } else {
 318     error("Invalid @ tag at the beginning of line \"%s\" line #%d", _token, _line_no);
 319     return false;
 320   }
 321 }
 322 
 323 void ClassListParser::skip_whitespaces() {
 324   while (*_token == ' ' || *_token == '\t') {
 325     _token ++;
 326   }
 327 }
 328 
 329 void ClassListParser::skip_non_whitespaces() {
 330   while (*_token && *_token != ' ' && *_token != '\t') {
 331     _token ++;
 332   }
 333 }
 334 
 335 void ClassListParser::parse_int(int* value) {
 336   skip_whitespaces();

 394 void ClassListParser::print_specified_interfaces() {
 395   const int n = _interfaces->length();
 396   jio_fprintf(defaultStream::error_stream(), "Currently specified interfaces[%d] = {\n", n);
 397   for (int i=0; i<n; i++) {
 398     InstanceKlass* k = lookup_class_by_id(_interfaces->at(i));
 399     jio_fprintf(defaultStream::error_stream(), "  %4d = %s\n", _interfaces->at(i), k->name()->as_klass_external_name());
 400   }
 401   jio_fprintf(defaultStream::error_stream(), "}\n");
 402 }
 403 
 404 void ClassListParser::print_actual_interfaces(InstanceKlass* ik) {
 405   int n = ik->local_interfaces()->length();
 406   jio_fprintf(defaultStream::error_stream(), "Actual interfaces[%d] = {\n", n);
 407   for (int i = 0; i < n; i++) {
 408     InstanceKlass* e = ik->local_interfaces()->at(i);
 409     jio_fprintf(defaultStream::error_stream(), "  %s\n", e->name()->as_klass_external_name());
 410   }
 411   jio_fprintf(defaultStream::error_stream(), "}\n");
 412 }
 413 
 414 void ClassListParser::error(const char* msg, ...) {
 415   va_list ap;
 416   va_start(ap, msg);





 417   int error_index = pointer_delta_as_int(_token, _line);
 418   if (error_index >= _line_len) {
 419     error_index = _line_len - 1;
 420   }
 421   if (error_index < 0) {
 422     error_index = 0;
 423   }
 424 
 425   jio_fprintf(defaultStream::error_stream(),
 426               "An error has occurred while processing class list file %s %d:%d.\n",
 427               _classlist_file, _line_no, (error_index + 1));
 428   jio_vfprintf(defaultStream::error_stream(), msg, ap);
 429 
 430   if (_line_len <= 0) {
 431     jio_fprintf(defaultStream::error_stream(), "\n");
 432   } else {
 433     jio_fprintf(defaultStream::error_stream(), ":\n");
 434     for (int i=0; i<_line_len; i++) {
 435       char c = _line[i];
 436       if (c == '\0') {
 437         jio_fprintf(defaultStream::error_stream(), "%s", " ");
 438       } else {
 439         jio_fprintf(defaultStream::error_stream(), "%c", c);
 440       }
 441     }
 442     jio_fprintf(defaultStream::error_stream(), "\n");
 443     for (int i=0; i<error_index; i++) {
 444       jio_fprintf(defaultStream::error_stream(), "%s", " ");
 445     }
 446     jio_fprintf(defaultStream::error_stream(), "^\n");
 447   }

 448 






 449   vm_exit_during_initialization("class list format error.", nullptr);
 450   va_end(ap);
 451 }
 452 










 453 // This function is used for loading classes for customized class loaders
 454 // during archive dumping.
 455 InstanceKlass* ClassListParser::load_class_from_source(Symbol* class_name, TRAPS) {
 456 #if !(defined(_LP64) && (defined(LINUX) || defined(__APPLE__) || defined(_WINDOWS)))
 457   // The only supported platforms are: (1) Linux/64-bit and (2) Solaris/64-bit and
 458   // (3) MacOSX/64-bit and (4) Windowss/64-bit
 459   // This #if condition should be in sync with the areCustomLoadersSupportedForCDS
 460   // method in test/lib/jdk/test/lib/Platform.java.
 461   error("AppCDS custom class loaders not supported on this platform");
 462 #endif
 463 
 464   if (!is_super_specified()) {
 465     error("If source location is specified, super class must be also specified");
 466   }
 467   if (!is_id_specified()) {
 468     error("If source location is specified, id must be also specified");
 469   }
 470   if (strncmp(_class_name, "java/", 5) == 0) {
 471     log_info(cds)("Prohibited package for non-bootstrap classes: %s.class from %s",
 472           _class_name, _source);

 707     error("Class %s implements the interface %s, but no interface has been specified in the input line",
 708           _class_name, interface_name->as_klass_external_name());
 709     ShouldNotReachHere();
 710   }
 711 
 712   int i;
 713   for (i=0; i<n; i++) {
 714     InstanceKlass* k = lookup_class_by_id(_interfaces->at(i));
 715     if (interface_name == k->name()) {
 716       return k;
 717     }
 718   }
 719 
 720   // interface_name is not specified by the "interfaces:" keyword.
 721   print_specified_interfaces();
 722   error("The interface %s implemented by class %s does not match any of the specified interface IDs",
 723         interface_name->as_klass_external_name(), _class_name);
 724   ShouldNotReachHere();
 725   return nullptr;
 726 }










































































































































































































































































   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 "precompiled.hpp"
  26 #include "cds/archiveUtils.hpp"
  27 #include "cds/cdsConfig.hpp"
  28 #include "cds/classListParser.hpp"
  29 #include "cds/classPrelinker.hpp"
  30 #include "cds/lambdaFormInvokers.hpp"
  31 #include "cds/metaspaceShared.hpp"
  32 #include "cds/unregisteredClasses.hpp"

  33 #include "classfile/javaClasses.inline.hpp"
  34 #include "classfile/symbolTable.hpp"
  35 #include "classfile/systemDictionary.hpp"
  36 #include "classfile/systemDictionaryShared.hpp"
  37 #include "classfile/vmClasses.hpp"
  38 #include "classfile/vmSymbols.hpp"
  39 #include "interpreter/bytecode.hpp"
  40 #include "interpreter/interpreterRuntime.hpp"
  41 #include "interpreter/linkResolver.hpp"
  42 #include "jimage.hpp"
  43 #include "jvm.h"
  44 #include "logging/log.hpp"
  45 #include "logging/logTag.hpp"
  46 #include "memory/oopFactory.hpp"
  47 #include "memory/resourceArea.hpp"
  48 #include "oops/constantPool.inline.hpp"
  49 #include "oops/cpCache.inline.hpp"
  50 #include "runtime/atomic.hpp"
  51 #include "runtime/handles.inline.hpp"
  52 #include "runtime/java.hpp"
  53 #include "runtime/javaCalls.hpp"
  54 #include "utilities/defaultStream.hpp"
  55 #include "utilities/macros.hpp"
  56 
  57 const char* ClassListParser::CLASS_REFLECTION_DATA_TAG = "@class-reflection-data";
  58 const char* ClassListParser::CONSTANT_POOL_TAG = "@cp";
  59 const char* ClassListParser::DYNAMIC_PROXY_TAG = "@dynamic-proxy";
  60 const char* ClassListParser::LAMBDA_FORM_TAG = "@lambda-form-invoker";
  61 const char* ClassListParser::LAMBDA_PROXY_TAG = "@lambda-proxy";
  62 const char* ClassListParser::LOADER_NEGATIVE_CACHE_TAG = "@loader-negative-cache";
  63 
  64 volatile Thread* ClassListParser::_parsing_thread = nullptr;
  65 ClassListParser* ClassListParser::_instance = nullptr;
  66 
  67 ClassListParser::ClassListParser(const char* file, ParseMode parse_mode) : _id2klass_table(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE) {
  68   log_info(cds)("Parsing %s%s", file,
  69                 (parse_mode == _parse_lambda_forms_invokers_only) ? " (lambda form invokers only)" : "");
  70   _classlist_file = file;
  71   _file = nullptr;
  72   // Use os::open() because neither fopen() nor os::fopen()
  73   // can handle long path name on Windows.
  74   int fd = os::open(file, O_RDONLY, S_IREAD);
  75   if (fd != -1) {
  76     // Obtain a File* from the file descriptor so that fgets()
  77     // can be used in parse_one_line()
  78     _file = os::fdopen(fd, "r");
  79   }
  80   if (_file == nullptr) {
  81     char errmsg[JVM_MAXPATHLEN];
  82     os::lasterror(errmsg, JVM_MAXPATHLEN);
  83     vm_exit_during_initialization("Loading classlist failed", errmsg);

 100 
 101 ClassListParser::~ClassListParser() {
 102   if (_file != nullptr) {
 103     fclose(_file);
 104   }
 105   Atomic::store(&_parsing_thread, (Thread*)nullptr);
 106   delete _indy_items;
 107   delete _interfaces;
 108   _instance = nullptr;
 109 }
 110 
 111 int ClassListParser::parse(TRAPS) {
 112   int class_count = 0;
 113 
 114   while (parse_one_line()) {
 115     if (lambda_form_line()) {
 116       // The current line is "@lambda-form-invoker ...". It has been recorded in LambdaFormInvokers,
 117       // and will be processed later.
 118       continue;
 119     }
 120     if (_constant_pool_line) {
 121       continue;
 122     }
 123     if (_class_reflection_data_line) {
 124       continue;
 125     }
 126     if (_loader_negative_cache_line) {
 127       continue;
 128     }
 129     if (_parse_mode == _parse_lambda_forms_invokers_only) {
 130       continue;
 131     }
 132 
 133     TempNewSymbol class_name_symbol = SymbolTable::new_symbol(_class_name);
 134     if (_indy_items->length() > 0) {
 135       // The current line is "@lambda-proxy class_name". Load the proxy class.
 136       resolve_indy(THREAD, class_name_symbol);
 137       class_count++;
 138       continue;
 139     }
 140 
 141     Klass* klass = load_current_class(class_name_symbol, THREAD);
 142     if (HAS_PENDING_EXCEPTION) {
 143       if (PENDING_EXCEPTION->is_a(vmClasses::OutOfMemoryError_klass())) {
 144         // If we have run out of memory, don't try to load the rest of the classes in
 145         // the classlist. Throw an exception, which will terminate the dumping process.
 146         return 0; // THROW
 147       }
 148 

 213           len --;
 214         } else {
 215           break;
 216         }
 217       }
 218       _line_len = len;
 219     }
 220 
 221     // valid line
 222     break;
 223   }
 224 
 225   _class_name = _line;
 226   _id = _unspecified;
 227   _super = _unspecified;
 228   _interfaces->clear();
 229   _source = nullptr;
 230   _interfaces_specified = false;
 231   _indy_items->clear();
 232   _lambda_form_line = false;
 233   _constant_pool_line = false;
 234   _class_reflection_data_line = false;
 235   _loader_negative_cache_line = false;
 236 
 237   if (_line[0] == '@') {
 238     return parse_at_tags();
 239   }
 240 
 241   if ((_token = strchr(_line, ' ')) == nullptr) {
 242     // No optional arguments are specified.
 243     return true;
 244   }
 245 
 246   // Mark the end of the name, and go to the next input char
 247   *_token++ = '\0';
 248 
 249   while (*_token) {
 250     skip_whitespaces();
 251 
 252     if (parse_uint_option("id:", &_id)) {
 253       continue;
 254     } else if (parse_uint_option("super:", &_super)) {
 255       check_already_loaded("Super class", _super);

 318 bool ClassListParser::parse_at_tags() {
 319   assert(_line[0] == '@', "must be");
 320   int offset;
 321   if ((offset = split_at_tag_from_line()) == 0) {
 322     return false;
 323   }
 324 
 325   if (strcmp(_token, LAMBDA_PROXY_TAG) == 0) {
 326     split_tokens_by_whitespace(offset);
 327     if (_indy_items->length() < 2) {
 328       error("Line with @ tag has too few items \"%s\" line #%d", _token, _line_no);
 329       return false;
 330     }
 331     // set the class name
 332     _class_name = _indy_items->at(0);
 333     return true;
 334   } else if (strcmp(_token, LAMBDA_FORM_TAG) == 0) {
 335     LambdaFormInvokers::append(os::strdup((const char*)(_line + offset), mtInternal));
 336     _lambda_form_line = true;
 337     return true;
 338   } else if (strcmp(_token, CONSTANT_POOL_TAG) == 0) {
 339     _token = _line + offset;
 340     _constant_pool_line = true;
 341     parse_constant_pool_tag();
 342     return true;
 343   } else if (strcmp(_token, CLASS_REFLECTION_DATA_TAG) == 0) {
 344     _token = _line + offset;
 345     _class_reflection_data_line = true;
 346     parse_class_reflection_data_tag();
 347     return true;
 348   } else if (strcmp(_token, DYNAMIC_PROXY_TAG) == 0) {
 349     _token = _line + offset;
 350     _constant_pool_line = true;
 351     parse_dynamic_proxy_tag();
 352     return true;
 353   } else if (strcmp(_token, LOADER_NEGATIVE_CACHE_TAG) == 0) {
 354     _token = _line + offset;
 355     _loader_negative_cache_line = true;
 356     parse_loader_negative_cache_tag();
 357     return true;
 358   } else {
 359     error("Invalid @ tag at the beginning of line \"%s\" line #%d", _token, _line_no);
 360     return false;
 361   }
 362 }
 363 
 364 void ClassListParser::skip_whitespaces() {
 365   while (*_token == ' ' || *_token == '\t') {
 366     _token ++;
 367   }
 368 }
 369 
 370 void ClassListParser::skip_non_whitespaces() {
 371   while (*_token && *_token != ' ' && *_token != '\t') {
 372     _token ++;
 373   }
 374 }
 375 
 376 void ClassListParser::parse_int(int* value) {
 377   skip_whitespaces();

 435 void ClassListParser::print_specified_interfaces() {
 436   const int n = _interfaces->length();
 437   jio_fprintf(defaultStream::error_stream(), "Currently specified interfaces[%d] = {\n", n);
 438   for (int i=0; i<n; i++) {
 439     InstanceKlass* k = lookup_class_by_id(_interfaces->at(i));
 440     jio_fprintf(defaultStream::error_stream(), "  %4d = %s\n", _interfaces->at(i), k->name()->as_klass_external_name());
 441   }
 442   jio_fprintf(defaultStream::error_stream(), "}\n");
 443 }
 444 
 445 void ClassListParser::print_actual_interfaces(InstanceKlass* ik) {
 446   int n = ik->local_interfaces()->length();
 447   jio_fprintf(defaultStream::error_stream(), "Actual interfaces[%d] = {\n", n);
 448   for (int i = 0; i < n; i++) {
 449     InstanceKlass* e = ik->local_interfaces()->at(i);
 450     jio_fprintf(defaultStream::error_stream(), "  %s\n", e->name()->as_klass_external_name());
 451   }
 452   jio_fprintf(defaultStream::error_stream(), "}\n");
 453 }
 454 
 455 void ClassListParser::print_diagnostic_info(outputStream* st, const char* msg, ...) {
 456   va_list ap;
 457   va_start(ap, msg);
 458   print_diagnostic_info(st, msg, ap);
 459   va_end(ap);
 460 }
 461 
 462 void ClassListParser::print_diagnostic_info(outputStream* st, const char* msg, va_list ap) {
 463   int error_index = pointer_delta_as_int(_token, _line);
 464   if (error_index >= _line_len) {
 465     error_index = _line_len - 1;
 466   }
 467   if (error_index < 0) {
 468     error_index = 0;
 469   }
 470 
 471   st->print("An error has occurred while processing class list file %s %d:%d.\n",
 472             _classlist_file, _line_no, (error_index + 1));
 473   st->vprint(msg, ap);

 474 
 475   if (_line_len <= 0) {
 476     st->print("\n");
 477   } else {
 478     st->print(":\n");
 479     for (int i=0; i<_line_len; i++) {
 480       char c = _line[i];
 481       if (c == '\0') {
 482         st->print("%s", " ");
 483       } else {
 484         st->print("%c", c);
 485       }
 486     }
 487     st->print("\n");
 488     for (int i=0; i<error_index; i++) {
 489       st->print("%s", " ");
 490     }
 491     st->print("^\n");
 492   }
 493 }
 494 
 495 void ClassListParser::error(const char* msg, ...) {
 496   va_list ap;
 497   va_start(ap, msg);
 498   LogTarget(Error, cds) lt;
 499   LogStream ls(lt);
 500   print_diagnostic_info(&ls, msg, ap);
 501   vm_exit_during_initialization("class list format error.", nullptr);
 502   va_end(ap);
 503 }
 504 
 505 void ClassListParser::constant_pool_resolution_warning(const char* msg, ...) {
 506   va_list ap;
 507   va_start(ap, msg);
 508   LogTarget(Warning, cds, resolve) lt;
 509   LogStream ls(lt);
 510   print_diagnostic_info(&ls, msg, ap);
 511   ls.print("Your classlist may be out of sync with the JDK or the application.");
 512   va_end(ap);
 513 }
 514 
 515 // This function is used for loading classes for customized class loaders
 516 // during archive dumping.
 517 InstanceKlass* ClassListParser::load_class_from_source(Symbol* class_name, TRAPS) {
 518 #if !(defined(_LP64) && (defined(LINUX) || defined(__APPLE__) || defined(_WINDOWS)))
 519   // The only supported platforms are: (1) Linux/64-bit and (2) Solaris/64-bit and
 520   // (3) MacOSX/64-bit and (4) Windowss/64-bit
 521   // This #if condition should be in sync with the areCustomLoadersSupportedForCDS
 522   // method in test/lib/jdk/test/lib/Platform.java.
 523   error("AppCDS custom class loaders not supported on this platform");
 524 #endif
 525 
 526   if (!is_super_specified()) {
 527     error("If source location is specified, super class must be also specified");
 528   }
 529   if (!is_id_specified()) {
 530     error("If source location is specified, id must be also specified");
 531   }
 532   if (strncmp(_class_name, "java/", 5) == 0) {
 533     log_info(cds)("Prohibited package for non-bootstrap classes: %s.class from %s",
 534           _class_name, _source);

 769     error("Class %s implements the interface %s, but no interface has been specified in the input line",
 770           _class_name, interface_name->as_klass_external_name());
 771     ShouldNotReachHere();
 772   }
 773 
 774   int i;
 775   for (i=0; i<n; i++) {
 776     InstanceKlass* k = lookup_class_by_id(_interfaces->at(i));
 777     if (interface_name == k->name()) {
 778       return k;
 779     }
 780   }
 781 
 782   // interface_name is not specified by the "interfaces:" keyword.
 783   print_specified_interfaces();
 784   error("The interface %s implemented by class %s does not match any of the specified interface IDs",
 785         interface_name->as_klass_external_name(), _class_name);
 786   ShouldNotReachHere();
 787   return nullptr;
 788 }
 789 
 790 InstanceKlass* ClassListParser::find_builtin_class_helper(JavaThread* current, Symbol* class_name_symbol, oop class_loader_oop) {
 791   Handle class_loader(current, class_loader_oop);
 792   Handle protection_domain;
 793   return SystemDictionary::find_instance_klass(current, class_name_symbol, class_loader, protection_domain);
 794 }
 795 
 796 InstanceKlass* ClassListParser::find_builtin_class(JavaThread* current, const char* class_name) {
 797   TempNewSymbol class_name_symbol = SymbolTable::new_symbol(class_name);
 798   InstanceKlass* ik;
 799 
 800   if ( (ik = find_builtin_class_helper(current, class_name_symbol, nullptr)) != nullptr
 801     || (ik = find_builtin_class_helper(current, class_name_symbol, SystemDictionary::java_platform_loader())) != nullptr
 802     || (ik = find_builtin_class_helper(current, class_name_symbol, SystemDictionary::java_system_loader())) != nullptr) {
 803     return ik;
 804   } else {
 805     return nullptr;
 806   }
 807 }
 808 
 809 void ClassListParser::parse_constant_pool_tag() {
 810   if (_parse_mode == _parse_lambda_forms_invokers_only) {
 811     return;
 812   }
 813 
 814   JavaThread* THREAD = JavaThread::current();
 815   skip_whitespaces();
 816   char* class_name = _token;
 817   skip_non_whitespaces();
 818   *_token = '\0';
 819   _token ++;
 820 
 821   InstanceKlass* ik = find_builtin_class(THREAD, class_name);
 822   if (ik == nullptr) {
 823     _token = class_name;
 824     if (strstr(class_name, "/$Proxy") != nullptr ||
 825         strstr(class_name, "MethodHandle$Species_") != nullptr) {
 826       // ignore -- TODO: we should filter these out in classListWriter.cpp
 827     } else {
 828       constant_pool_resolution_warning("class %s is not (yet) loaded by one of the built-in loaders", class_name);
 829     }
 830     return;
 831   }
 832 
 833   ResourceMark rm(THREAD);
 834   constantPoolHandle cp(THREAD, ik->constants());
 835   GrowableArray<bool> preresolve_list(cp->length(), cp->length(), false);
 836   bool preresolve_class = false;
 837   bool preresolve_fmi = false;
 838   bool preresolve_indy = false;
 839   
 840   while (*_token) {
 841     int cp_index;
 842     skip_whitespaces();
 843     parse_uint(&cp_index);
 844     if (cp_index < 1 || cp_index >= cp->length()) {
 845       constant_pool_resolution_warning("Invalid constant pool index %d", cp_index);
 846       return;
 847     } else {
 848       preresolve_list.at_put(cp_index, true);
 849     }
 850     constantTag cp_tag = cp->tag_at(cp_index);
 851     switch (cp_tag.value()) {
 852     case JVM_CONSTANT_UnresolvedClass:
 853       preresolve_class = true;
 854       break;
 855     case JVM_CONSTANT_UnresolvedClassInError:
 856     case JVM_CONSTANT_Class:
 857       // ignore
 858     case JVM_CONSTANT_Fieldref:
 859     case JVM_CONSTANT_Methodref:
 860     case JVM_CONSTANT_InterfaceMethodref:
 861       preresolve_fmi = true;
 862       break;
 863     case JVM_CONSTANT_InvokeDynamic:
 864       preresolve_indy = true;
 865       break;
 866     default:
 867       constant_pool_resolution_warning("Unsupported constant pool index %d: %s (type=%d)",
 868                                        cp_index, cp_tag.internal_name(), cp_tag.value());
 869       return;
 870     }
 871   }
 872 
 873   if (preresolve_class) {
 874     ClassPrelinker::preresolve_class_cp_entries(THREAD, ik, &preresolve_list);
 875   }
 876   if (preresolve_fmi) {
 877 // FIXME: too coarse; doesn't cover resolution of Class entries
 878 //    JavaThread::NoJavaCodeMark no_java_code(THREAD); // ensure no clinits are exectued
 879     ClassPrelinker::preresolve_field_and_method_cp_entries(THREAD, ik, &preresolve_list);
 880   }
 881   if (preresolve_indy) {
 882     ClassPrelinker::preresolve_indy_cp_entries(THREAD, ik, &preresolve_list);
 883   }
 884 }
 885 
 886 void ClassListParser::parse_class_reflection_data_tag() {
 887   if (_parse_mode == _parse_lambda_forms_invokers_only) {
 888     return;
 889   }
 890 
 891   JavaThread* THREAD = JavaThread::current();
 892   skip_whitespaces();
 893   char* class_name = _token;
 894   skip_non_whitespaces();
 895   *_token = '\0';
 896   _token ++;
 897 
 898   InstanceKlass* ik = find_builtin_class(THREAD, class_name);
 899   if (ik == nullptr) {
 900     _token = class_name;
 901     if (strstr(class_name, "/$Proxy") != nullptr ||
 902         strstr(class_name, "MethodHandle$Species_") != nullptr) {
 903       // ignore -- TODO: we should filter these out in classListWriter.cpp
 904     } else {
 905       warning("%s: class not found: %s", CLASS_REFLECTION_DATA_TAG, class_name);
 906     }
 907     return;
 908   }
 909 
 910   ResourceMark rm(THREAD);
 911 
 912   int rd_flags = _unspecified;
 913   while (*_token) {
 914     skip_whitespaces();
 915     if (rd_flags != _unspecified) {
 916       error("rd_flags specified twice");
 917       return;
 918     }
 919     parse_uint(&rd_flags);
 920   }
 921   if (rd_flags == _unspecified) {
 922     error("no rd_flags specified");
 923     return;
 924   }
 925 
 926   if (ArchiveReflectionData) {
 927     ClassPrelinker::generate_reflection_data(THREAD, ik, rd_flags);
 928   }
 929 }
 930 
 931 oop ClassListParser::loader_from_type(const char* loader_type) {
 932   oop loader;
 933   if (!ArchiveUtils::builtin_loader_from_type(loader_type, &loader)) {
 934     error("Unknown loader %s", loader_type);
 935   }
 936   return loader;
 937 }
 938 
 939 void ClassListParser::parse_dynamic_proxy_tag() {
 940   if (_parse_mode == _parse_lambda_forms_invokers_only) {
 941     return;
 942   }
 943 
 944   skip_whitespaces();
 945   char* loader_type = _token;
 946   skip_non_whitespaces();
 947   *_token = '\0';
 948   _token ++;
 949 
 950   skip_whitespaces();
 951   char* proxy_name_str = _token;
 952   skip_non_whitespaces();
 953   *_token = '\0';
 954   _token ++;
 955 
 956   skip_whitespaces();
 957   int access_flags;
 958   parse_uint(&access_flags);
 959 
 960   skip_whitespaces();
 961   int num_intfs;
 962   parse_uint(&num_intfs);
 963 
 964   JavaThread* THREAD = JavaThread::current();
 965   Handle loader(THREAD, loader_from_type(loader_type));
 966   Handle proxy_name(THREAD, java_lang_String::create_oop_from_str(proxy_name_str, THREAD));
 967   if (HAS_PENDING_EXCEPTION) {
 968     error("Out of memory");
 969   }
 970 
 971   objArrayHandle interfaces(THREAD, oopFactory::new_objArray(vmClasses::Class_klass(), num_intfs, THREAD));
 972   if (HAS_PENDING_EXCEPTION) {
 973     error("Out of memory");
 974   }
 975 
 976   for (int i = 0; i < num_intfs; i++) {
 977     skip_whitespaces();
 978     char* intf_name = _token;
 979     skip_non_whitespaces();
 980     *_token = '\0';
 981     _token ++;
 982 
 983     InstanceKlass* ik = find_builtin_class(THREAD, intf_name);
 984     if (ik != nullptr) {
 985       interfaces()->obj_at_put(i, ik->java_mirror());
 986     } else {
 987       error("Unknown class %s", intf_name);
 988     }
 989   }
 990 
 991   if (strncmp("jdk.proxy", proxy_name_str, 9) != 0) {
 992     return;
 993   }
 994 
 995   ClassPrelinker::define_dynamic_proxy_class(loader, proxy_name, interfaces, access_flags, THREAD);
 996   if (HAS_PENDING_EXCEPTION) {
 997     PENDING_EXCEPTION->print_on(tty);
 998     error("defineProxyClassForCDS failed");
 999   }
1000 }
1001 
1002 void ClassListParser::parse_loader_negative_cache_tag() {
1003   skip_whitespaces();
1004   char* loader_type = _token;
1005   skip_non_whitespaces();
1006   *_token = '\0';
1007   _token ++;
1008 
1009   oop loader;
1010   Klass* loader_klass;
1011   if (!strcmp(loader_type, "app")) {
1012     loader = SystemDictionary::java_system_loader();
1013     loader_klass = vmClasses::jdk_internal_loader_ClassLoaders_AppClassLoader_klass();
1014   } else if (!strcmp(loader_type, "platform")) {
1015     loader = SystemDictionary::java_platform_loader();
1016     loader_klass = vmClasses::jdk_internal_loader_ClassLoaders_PlatformClassLoader_klass();
1017   } else {
1018     warning("%s: unrecognized loader type %s is ignored", LOADER_NEGATIVE_CACHE_TAG, loader_type);
1019     return;
1020   }
1021 
1022   char* contents = _token;
1023   skip_non_whitespaces();
1024   *_token = '\0';
1025   _token ++;
1026 
1027   if (ArchiveLoaderLookupCache) {
1028     TempNewSymbol method = SymbolTable::new_symbol("generateNegativeLookupCache");
1029     TempNewSymbol signature = SymbolTable::new_symbol("(Ljava/lang/String;)V");
1030 
1031     EXCEPTION_MARK;
1032     HandleMark hm(THREAD);
1033     JavaCallArguments args(Handle(THREAD, loader));
1034     Handle contents_h = java_lang_String::create_from_str(contents, THREAD);
1035     args.push_oop(contents_h);
1036     JavaValue result(T_VOID);
1037     JavaCalls::call_virtual(&result,
1038                             loader_klass,
1039                             method,
1040                             signature,
1041                             &args, THREAD);
1042     if (HAS_PENDING_EXCEPTION) {
1043       Handle exc_handle(THREAD, PENDING_EXCEPTION);
1044       CLEAR_PENDING_EXCEPTION;
1045 
1046       log_warning(cds)("Exception during BuiltinClassLoader::generateNegativeLookupCache() call for %s loader", loader_type);
1047       LogStreamHandle(Debug, cds) log;
1048       if (log.is_enabled()) {
1049         java_lang_Throwable::print_stack_trace(exc_handle, &log);
1050       }
1051     }
1052   }
1053 }
< prev index next >