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_SHAREDPATHSMISCINFO_HPP
26 #define SHARE_VM_CLASSFILE_SHAREDPATHSMISCINFO_HPP
27
28 #include "runtime/os.hpp"
29
30 // During dumping time, when processing class paths, we build up the dump-time
31 // classpath. The JAR files that exist are stored in the list ClassLoader::_first_entry.
32 // However, we need to store other "misc" information for run-time checking, such as
33 //
34 // + The values of Arguments::get_sysclasspath() used during dumping.
35 //
36 // + The meta-index file(s) used during dumping (incl modification time and size)
37 //
38 // + The class path elements specified during dumping but did not exist --
39 // these elements must also be specified at run time, and they also must not
40 // exist at run time.
41 //
42 // These misc items are stored in a linear buffer in SharedPathsMiscInfo.
43 // The storage format is stream oriented to minimize its size.
44 //
45 // When writing the information to the archive file, SharedPathsMiscInfo is stored in
46 // the archive file header. At run-time, this information is used only during initialization
47 // (accessed using read() instead of mmap()), and is deallocated afterwards to save space.
87 _buf_size = size;
88 _allocated = false;
89 }
90 ~SharedPathsMiscInfo() {
91 if (_allocated) {
92 FREE_C_HEAP_ARRAY(char, _buf_start);
93 }
94 }
95 int get_used_bytes() {
96 return _cur_ptr - _buf_start;
97 }
98 void* buffer() {
99 return _buf_start;
100 }
101
102 // writing --
103
104 // The path must not exist at run-time
105 void add_nonexist_path(const char* path) {
106 add_path(path, NON_EXIST);
107 }
108
109 // The path must exist and have required size and modification time
110 void add_required_file(const char* path) {
111 add_path(path, REQUIRED);
112
113 struct stat st;
114 if (os::stat(path, &st) != 0) {
115 assert(0, "sanity");
116 ClassLoader::exit_with_path_failure("failed to os::stat(%s)", path); // should not happen
117 }
118 write_time(st.st_mtime);
119 write_long(st.st_size);
120 }
121
122 // The path must exist, and must contain exactly <num_entries> files/dirs
123 void add_boot_classpath(const char* path) {
124 add_path(path, BOOT);
125 }
126 int write_jint(jint num) {
127 write(&num, sizeof(num));
128 return 0;
129 }
130 void write_time(time_t t) {
131 write(&t, sizeof(t));
132 }
133 void write_long(long l) {
134 write(&l, sizeof(l));
135 }
136
137 bool dump_to_file(int fd) {
138 int n = get_used_bytes();
139 return (os::write(fd, _buf_start, n) == (size_t)n);
|
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_SHAREDPATHSMISCINFO_HPP
26 #define SHARE_VM_CLASSFILE_SHAREDPATHSMISCINFO_HPP
27
28 #include "classfile/classLoader.hpp"
29 #include "runtime/os.hpp"
30
31 // During dumping time, when processing class paths, we build up the dump-time
32 // classpath. The JAR files that exist are stored in the list ClassLoader::_first_entry.
33 // However, we need to store other "misc" information for run-time checking, such as
34 //
35 // + The values of Arguments::get_sysclasspath() used during dumping.
36 //
37 // + The meta-index file(s) used during dumping (incl modification time and size)
38 //
39 // + The class path elements specified during dumping but did not exist --
40 // these elements must also be specified at run time, and they also must not
41 // exist at run time.
42 //
43 // These misc items are stored in a linear buffer in SharedPathsMiscInfo.
44 // The storage format is stream oriented to minimize its size.
45 //
46 // When writing the information to the archive file, SharedPathsMiscInfo is stored in
47 // the archive file header. At run-time, this information is used only during initialization
48 // (accessed using read() instead of mmap()), and is deallocated afterwards to save space.
88 _buf_size = size;
89 _allocated = false;
90 }
91 ~SharedPathsMiscInfo() {
92 if (_allocated) {
93 FREE_C_HEAP_ARRAY(char, _buf_start);
94 }
95 }
96 int get_used_bytes() {
97 return _cur_ptr - _buf_start;
98 }
99 void* buffer() {
100 return _buf_start;
101 }
102
103 // writing --
104
105 // The path must not exist at run-time
106 void add_nonexist_path(const char* path) {
107 add_path(path, NON_EXIST);
108 }
109
110 // The path must exist, and must contain exactly <num_entries> files/dirs
111 void add_boot_classpath(const char* path) {
112 add_path(path, BOOT);
113 }
114 int write_jint(jint num) {
115 write(&num, sizeof(num));
116 return 0;
117 }
118 void write_time(time_t t) {
119 write(&t, sizeof(t));
120 }
121 void write_long(long l) {
122 write(&l, sizeof(l));
123 }
124
125 bool dump_to_file(int fd) {
126 int n = get_used_bytes();
127 return (os::write(fd, _buf_start, n) == (size_t)n);
|