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