src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSection.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho

src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSection.java

Print this page




  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.macho;
  25 
  26 import java.nio.ByteBuffer;
  27 import java.nio.ByteOrder;
  28 
  29 import jdk.tools.jaotc.binformat.macho.MachO;
  30 import jdk.tools.jaotc.binformat.macho.MachO.section_64;
  31 import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
  32 
  33 public class MachOSection {
  34     ByteBuffer section;
  35     byte [] data;
  36     boolean hasrelocations;
  37 
  38     public MachOSection(String sectName, String segName, byte [] sectData, int sectFlags, boolean hasRelocations) {
  39         section = MachOByteBuffer.allocate(section_64.totalsize);
  40 
  41         // TODO: Hotspot uses long section names.
  42         //       They are getting truncated.
  43         //       Is this a problem??
  44         byte[] sectNameBytes = sectName.getBytes();
  45         int sectNameMax = section_64.sectname.sz < sectNameBytes.length ?
  46                          section_64.sectname.sz : sectNameBytes.length;
  47 
  48         for (int i = 0; i < sectNameMax; i++)
  49             section.put(section_64.sectname.off+i, sectNameBytes[i]);
  50 
  51         byte[] segNameBytes = segName.getBytes();
  52         int segNameMax = section_64.segname.sz < segNameBytes.length ?
  53                          section_64.segname.sz : segNameBytes.length;
  54 
  55         for (int i = 0; i < segNameMax; i++)
  56             section.put(section_64.segname.off+i, segNameBytes[i]);
  57 
  58         section.putLong(section_64.size.off, sectData.length);
  59 
  60         // For now use 8 byte alignment
  61         section.putInt(section_64.align.off, 3);
  62 
  63         section.putInt(section_64.flags.off, sectFlags);
  64 
  65         data = sectData;
  66 
  67         hasrelocations = hasRelocations;
  68     }
  69 
  70     public long getSize() {
  71         return section.getLong(section_64.size.off);
  72     }
  73 
  74     public int getAlign() {
  75         return (1 << section.getInt(section_64.align.off));
  76     }
  77 
  78     public byte[] getArray() {
  79         return section.array();
  80     }
  81 




  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.macho;
  25 
  26 import java.nio.ByteBuffer;
  27 import java.nio.ByteOrder;
  28 
  29 import jdk.tools.jaotc.binformat.macho.MachO;
  30 import jdk.tools.jaotc.binformat.macho.MachO.section_64;
  31 import jdk.tools.jaotc.binformat.macho.MachOByteBuffer;
  32 
  33 public class MachOSection {
  34     ByteBuffer section;
  35     byte [] data;
  36     boolean hasrelocations;
  37 
  38     public MachOSection(String sectName, String segName, byte [] sectData, int sectFlags, boolean hasRelocations, int align) {
  39         section = MachOByteBuffer.allocate(section_64.totalsize);
  40 
  41         // TODO: Hotspot uses long section names.
  42         //       They are getting truncated.
  43         //       Is this a problem??
  44         byte[] sectNameBytes = sectName.getBytes();
  45         int sectNameMax = section_64.sectname.sz < sectNameBytes.length ?
  46                          section_64.sectname.sz : sectNameBytes.length;
  47 
  48         for (int i = 0; i < sectNameMax; i++)
  49             section.put(section_64.sectname.off+i, sectNameBytes[i]);
  50 
  51         byte[] segNameBytes = segName.getBytes();
  52         int segNameMax = section_64.segname.sz < segNameBytes.length ?
  53                          section_64.segname.sz : segNameBytes.length;
  54 
  55         for (int i = 0; i < segNameMax; i++)
  56             section.put(section_64.segname.off+i, segNameBytes[i]);
  57 
  58         section.putLong(section_64.size.off, sectData.length);
  59 
  60         section.putInt(section_64.align.off, align);

  61 
  62         section.putInt(section_64.flags.off, sectFlags);
  63 
  64         data = sectData;
  65 
  66         hasrelocations = hasRelocations;
  67     }
  68 
  69     public long getSize() {
  70         return section.getLong(section_64.size.off);
  71     }
  72 
  73     public int getAlign() {
  74         return (1 << section.getInt(section_64.align.off));
  75     }
  76 
  77     public byte[] getArray() {
  78         return section.array();
  79     }
  80 


src/jdk.aot/share/classes/jdk.tools.jaotc.binformat/src/jdk/tools/jaotc/binformat/macho/MachOSection.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File