1 /*
2 * Copyright (c) 2016, 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 package jdk.tools.jaotc.binformat;
25
26 import java.io.ByteArrayOutputStream;
27 import java.io.DataOutputStream;
28 import java.io.IOException;
29
30 public class HeaderContainer {
31
32 private static final int CURRENT_VERSION = 1;
33 private final ReadOnlyDataContainer container;
34 // int _version;
35 // int _class_count;
36 // int _method_count;
37 // int _metaspace_got_size;
38 // int _metadata_got_size;
39 // int _oop_got_size;
40 // int _jvm_version_offset;
41
42 public HeaderContainer(String jvmVersion, ReadOnlyDataContainer container) {
43 try {
44 byte[] filler = new byte[4 * 7];
45 container.appendBytes(filler);
46
47 // Store JVM version string at the end of header section.
48 ByteArrayOutputStream bout = new ByteArrayOutputStream();
49 DataOutputStream out = new DataOutputStream(bout);
50 out.writeUTF(jvmVersion);
51 out.writeShort(0); // Terminate by 0.
52 byte[] b = bout.toByteArray();
53 container.appendBytes(b, 0, b.length);
54 } catch (IOException e) {
55 throw new InternalError("Failed to append bytes to header section", e);
56 }
57
59 this.container.putIntAt(0 * 4, CURRENT_VERSION);
60 this.container.putIntAt(6 * 4, 7 * 4); // JVM version string offset
61 }
62
63 public String getContainerName() {
64 return container.getContainerName();
65 }
66
67 public ReadOnlyDataContainer getContainer() {
68 return container;
69 }
70
71 public void setClassesCount(int count) {
72 this.container.putIntAt(1 * 4, count);
73 }
74
75 public void setMethodsCount(int count) {
76 this.container.putIntAt(2 * 4, count);
77 }
78
79 public void setMetaspaceGotSize(int size) {
80 this.container.putIntAt(3 * 4, size);
81 }
82
83 public void setMetadataGotSize(int size) {
84 this.container.putIntAt(4 * 4, size);
85 }
86
87 public void setOopGotSize(int size) {
88 this.container.putIntAt(5 * 4, size);
89 }
90
91 }
|
1 /*
2 * Copyright (c) 2016, 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 package jdk.tools.jaotc.binformat;
25
26 import java.io.ByteArrayOutputStream;
27 import java.io.DataOutputStream;
28 import java.io.IOException;
29
30 public final class HeaderContainer {
31
32 private static final int CURRENT_VERSION = 1;
33 private final ReadOnlyDataContainer container;
34
35 // int _version;
36 // int _class_count;
37 // int _method_count;
38 // int _klasses_got_size;
39 // int _metadata_got_size;
40 // int _oop_got_size;
41 // int _jvm_version_offset;
42
43 public HeaderContainer(String jvmVersion, ReadOnlyDataContainer container) {
44 try {
45 byte[] filler = new byte[4 * 7];
46 container.appendBytes(filler);
47
48 // Store JVM version string at the end of header section.
49 ByteArrayOutputStream bout = new ByteArrayOutputStream();
50 DataOutputStream out = new DataOutputStream(bout);
51 out.writeUTF(jvmVersion);
52 out.writeShort(0); // Terminate by 0.
53 byte[] b = bout.toByteArray();
54 container.appendBytes(b, 0, b.length);
55 } catch (IOException e) {
56 throw new InternalError("Failed to append bytes to header section", e);
57 }
58
60 this.container.putIntAt(0 * 4, CURRENT_VERSION);
61 this.container.putIntAt(6 * 4, 7 * 4); // JVM version string offset
62 }
63
64 public String getContainerName() {
65 return container.getContainerName();
66 }
67
68 public ReadOnlyDataContainer getContainer() {
69 return container;
70 }
71
72 public void setClassesCount(int count) {
73 this.container.putIntAt(1 * 4, count);
74 }
75
76 public void setMethodsCount(int count) {
77 this.container.putIntAt(2 * 4, count);
78 }
79
80 public void setKlassesGotSize(int size) {
81 this.container.putIntAt(3 * 4, size);
82 }
83
84 public void setMetadataGotSize(int size) {
85 this.container.putIntAt(4 * 4, size);
86 }
87
88 public void setOopGotSize(int size) {
89 this.container.putIntAt(5 * 4, size);
90 }
91
92 }
|