annotate agent/src/share/classes/sun/jvm/hotspot/asm/sparc/SPARCDisassembler.java @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents a61af66fc99e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.asm.sparc;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import sun.jvm.hotspot.asm.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 public abstract class SPARCDisassembler extends Disassembler
a61af66fc99e Initial load
duke
parents:
diff changeset
32 implements /* imports */ SPARCOpcodes, RTLDataTypes, RTLOperations {
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // instruction cache - Map<Integer, Instruction>.
a61af66fc99e Initial load
duke
parents:
diff changeset
35 protected static Map instructionCache = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
36 protected final SPARCInstructionFactory factory;
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 public SPARCDisassembler(long startPc, byte[] code, SPARCInstructionFactory factory) {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 super(startPc, code);
a61af66fc99e Initial load
duke
parents:
diff changeset
40 this.factory = factory;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 }
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 protected static InstructionDecoder illegalDecoder = new IllegalInstructionDecoder();
a61af66fc99e Initial load
duke
parents:
diff changeset
44 protected static InstructionDecoder callDecoder = new CallDecoder();
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // direct call instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
47 protected Instruction decodeFormat1Instruction(int instruction) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 return callDecoder.decode(instruction, factory);
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 protected abstract InstructionDecoder getFormat2Decoder(int op2);
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 protected Instruction decodeFormat2Instruction(int instruction) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 int op2 = (instruction & OP_2_MASK) >>> OP_2_START_BIT;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 InstructionDecoder decoder = getFormat2Decoder(op2);
a61af66fc99e Initial load
duke
parents:
diff changeset
56 return decoder.decode(instruction, factory);
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // "op3" - used in format 3 & 3A instructions - 6 bits width
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 protected static int getOp3(int instruction) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 return (instruction & OP_3_MASK) >>> OP_3_START_BIT;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // op3 opcodes is broken up into column and row. MSB 2 bits form column.
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // LSB 4 bits form row number.
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 protected static int getOp3Row(int op3) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 return op3 & 0xF;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 protected static int getOp3Column(int op3) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 return (op3 >>> 4) & 0x3;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 protected abstract InstructionDecoder getFormat3Decoder(int row, int column);
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // memory instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
79 protected Instruction decodeFormat3Instruction(int instruction) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 int op3 = getOp3(instruction);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 int row = getOp3Row(op3);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 int column = getOp3Column(op3);
a61af66fc99e Initial load
duke
parents:
diff changeset
83 return getFormat3Decoder(row, column).decode(instruction, factory);
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 protected abstract InstructionDecoder getFormat3ADecoder(int row, int column);
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // arithmetic, logic, shift and the rest
a61af66fc99e Initial load
duke
parents:
diff changeset
89 protected Instruction decodeFormat3AInstruction(int instruction) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 int op3 = getOp3(instruction);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 int row = getOp3Row(op3);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 int column = getOp3Column(op3);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 return getFormat3ADecoder(row, column).decode(instruction, factory);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 public void decode(InstructionVisitor visitor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 visitor.prologue();
a61af66fc99e Initial load
duke
parents:
diff changeset
98 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 DataInputStream dis = new DataInputStream(new ByteArrayInputStream(code));
a61af66fc99e Initial load
duke
parents:
diff changeset
100 int instruction = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 int format = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 Instruction instr = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 int len = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 while (len < code.length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 instr = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 instruction = dis.readInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // check whether we have this in cache.
a61af66fc99e Initial load
duke
parents:
diff changeset
109 instr = (Instruction) instructionCache.get(new Integer(instruction));
a61af66fc99e Initial load
duke
parents:
diff changeset
110 if (instr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 format = (instruction & FORMAT_MASK) >>> FORMAT_START_BIT;
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 switch (format) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 case FORMAT_2: // 0
a61af66fc99e Initial load
duke
parents:
diff changeset
115 instr = decodeFormat2Instruction(instruction);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 case FORMAT_1: // 1
a61af66fc99e Initial load
duke
parents:
diff changeset
119 instr = decodeFormat1Instruction(instruction);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 case FORMAT_3A: // 2
a61af66fc99e Initial load
duke
parents:
diff changeset
123 instr = decodeFormat3AInstruction(instruction);
a61af66fc99e Initial load
duke
parents:
diff changeset
124 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 case FORMAT_3: // 3
a61af66fc99e Initial load
duke
parents:
diff changeset
127 instr = decodeFormat3Instruction(instruction);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // add the new instruction to cache.
a61af66fc99e Initial load
duke
parents:
diff changeset
132 instructionCache.put(new Integer(instruction), instr);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 visitor.visit(startPc + len, instr);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 len += 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138 } catch (IOException ioExp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // ignore, can't happen
a61af66fc99e Initial load
duke
parents:
diff changeset
140 } finally {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 visitor.epilogue();
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }