1 /*
   2  * Copyright (c) 2014, 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  *
  23  */
  24 
  25 #ifndef SHARE_VM_CLASSFILE_SHAREDCLASSUTIL_HPP
  26 #define SHARE_VM_CLASSFILE_SHAREDCLASSUTIL_HPP
  27 
  28 #include "classfile/sharedPathsMiscInfo.hpp"
  29 #include "memory/filemap.hpp"
  30 #include "classfile/classLoaderExt.hpp"
  31 #include "classfile/dictionary.hpp"
  32 #include "classfile/systemDictionaryShared.hpp"
  33 #include "oops/klass.hpp"
  34 
  35 class FileMapHeaderExt: public FileMapInfo::FileMapHeader {
  36 public:
  37   jshort _app_class_paths_start_index;  // Index of first app classpath entry
  38   jshort _app_module_paths_start_index; // Index of first module path entry
  39   bool   _verify_local;                 // BytecodeVerificationLocal setting
  40   bool   _verify_remote;                // BytecodeVerificationRemote setting
  41   bool   _has_platform_or_app_classes;  // Archive contains app classes
  42 
  43   FileMapHeaderExt() {
  44     _has_platform_or_app_classes = true;
  45   }
  46   virtual void populate(FileMapInfo* mapinfo, size_t alignment);
  47   virtual bool validate();
  48 };
  49 
  50 // In addition to SharedPathsMiscInfo, the following information is also stored
  51 //
  52 //
  53 // + The value of Arguments::get_appclasspath() used during dumping.
  54 //
  55 class SharedPathsMiscInfoExt : public SharedPathsMiscInfo {
  56 private:
  57   int   _app_offset;
  58 public:
  59   enum {
  60     APP       = 5,
  61     MODULE    = 6
  62   };
  63 
  64   virtual const char* type_name(int type) {
  65     switch (type) {
  66     case APP:     return "APP";
  67     case MODULE:  return "MODULE";
  68     default:      return SharedPathsMiscInfo::type_name(type);
  69     }
  70   }
  71 
  72   virtual void print_path(outputStream* out, int type, const char* path);
  73 
  74   SharedPathsMiscInfoExt() : SharedPathsMiscInfo() {
  75     _app_offset = 0;
  76   }
  77   SharedPathsMiscInfoExt(char* buf, int size) : SharedPathsMiscInfo(buf, size) {
  78     _app_offset = 0;
  79   }
  80 
  81   virtual bool check(jint type, const char* path);
  82 
  83   void add_app_classpath(const char* path) {
  84     add_path(path, APP);
  85   }
  86 
  87   void record_app_offset() {
  88     _app_offset = get_used_bytes();
  89   }
  90   void pop_app() {
  91     _cur_ptr = _buf_start + _app_offset;
  92     write_jint(0);
  93   }
  94 };
  95 
  96 class SharedClassPathEntryExt: public SharedClassPathEntry {
  97 public:
  98   //Maniest attributes
  99   bool _is_signed;
 100   void set_manifest(Array<u1>* manifest) {
 101     _manifest = manifest;
 102   }
 103 };
 104 
 105 class SharedClassUtil : AllStatic {
 106 public:
 107   static SharedPathsMiscInfo* allocate_shared_paths_misc_info() {
 108     return new SharedPathsMiscInfoExt();
 109   }
 110 
 111   static SharedPathsMiscInfo* allocate_shared_paths_misc_info(char* buf, int size) {
 112     return new SharedPathsMiscInfoExt(buf, size);
 113   }
 114 
 115   static FileMapInfo::FileMapHeader* allocate_file_map_header() {
 116     return new FileMapHeaderExt();
 117   }
 118 
 119   static size_t file_map_header_size() {
 120     return sizeof(FileMapHeaderExt);
 121   }
 122 
 123   static size_t shared_class_path_entry_size() {
 124     return sizeof(SharedClassPathEntryExt);
 125   }
 126 
 127   static void update_shared_classpath(ClassPathEntry *cpe, SharedClassPathEntry* ent, TRAPS);
 128   static void initialize(TRAPS);
 129 
 130 private:
 131   static void read_extra_data(const char* filename, TRAPS);
 132 
 133 public:
 134   static bool is_classpath_entry_signed(int classpath_index);
 135 };
 136 
 137 #endif // SHARE_VM_CLASSFILE_SHAREDCLASSUTIL_HPP