1 /* BytePtr.java -- Container for bytes from a memory image.
2 Copyright (C) 2007 Free Software Foundation
4 This file is part of libgcj.
6 This software is copyrighted work licensed under the terms of the
7 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
10 package gnu
.gcj
.tools
.gc_analyze
;
12 import java
.nio
.ByteBuffer
;
19 BytePtr(ByteBuffer b
, int ws
)
27 return content
.limit();
30 public int getByte(int offset
)
32 return content
.get(offset
);
35 public int getInt(int n
)
37 return content
.getInt(n
* 4);
40 public int getShort(int n
)
42 return content
.getShort(n
* 2);
45 public long getWord(int n
)
48 return 0xffffffffL
& content
.getInt(n
* 4);
50 return content
.getLong(n
* 8);
53 public int intsPerWord()
55 return (4 == wordSize
) ?
1 : 2;
58 public BytePtr
getRegion(int offset
, int size
)
60 int oldLimit
= content
.limit();
61 content
.position(offset
);
62 content
.limit(offset
+ size
);
63 ByteBuffer n
= content
.slice();
65 content
.limit(oldLimit
);
67 return new BytePtr(n
, wordSize
);
70 public void setInt(int a
, int n
)
72 content
.putInt(a
* 4, n
);
77 // 38 5a f4 2a 50 bd 04 10 10 00 00 00 0e 00 00 00 8Z.*P...........
79 StringBuilder b
= new StringBuilder(67);
80 for (i
= 0; i
< 66; i
++)
87 for (int j
= 0; j
< 16; j
++)
91 if (k
< content
.limit())
93 int v
= 0xff & getByte(k
);
96 b
.setCharAt(j
* 3 + 0,
97 (char)(v1
>= 10 ?
'a' - 10 + v1
: v1
+ '0'));
99 b
.setCharAt(j
* 3 + 1,
100 (char)(v1
>= 10 ?
'a' - 10 + v1
: v1
+ '0'));
102 b
.setCharAt(j
+ 50, (char)((v
>= 32 && v
<= 127) ? v
: '.'));
106 b
.setCharAt(j
* 3 + 0, ' ');
107 b
.setCharAt(j
* 3 + 1, ' ');
108 b
.setCharAt(j
+ 50, ' ');
113 } while (i
< content
.limit());