1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.debugger
;
12 import cc
.squirreljme
.jdwp
.JDWPCommandSet
;
13 import cc
.squirreljme
.jdwp
.JDWPCommandSetReferenceType
;
14 import cc
.squirreljme
.jdwp
.JDWPId
;
15 import cc
.squirreljme
.jdwp
.JDWPPacket
;
16 import cc
.squirreljme
.runtime
.cldc
.debug
.Debugging
;
17 import java
.lang
.ref
.WeakReference
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
20 import net
.multiphasicapps
.classfile
.Pool
;
23 * Stores remote byte code information.
27 public class InfoByteCode
30 /** The referenced method. */
31 protected final WeakReference
<InfoMethod
> method
;
33 /** The constant pool of the class this is in. */
34 protected final Pool constantPool
;
36 /** The byte code of the method. */
37 private final byte[] _byteCode
;
39 /** The byte code instructions. */
40 private volatile InstructionViewer
[] _instructions
;
43 * Initializes the byte code information.
45 * @param __state The debugger state.
46 * @param __id The ID number of this info.
47 * @param __method The owning method.
48 * @param __constantPool The constant pool.
49 * @param __byteCode The raw byte code.
52 public InfoByteCode(DebuggerState __state
, JDWPId __id
,
53 InfoMethod __method
, Pool __constantPool
, byte[] __byteCode
)
54 throws NullPointerException
56 super(__state
, __id
, InfoKind
.BYTE_CODE
);
58 this.method
= new WeakReference
<>(__method
);
59 this.constantPool
= __constantPool
;
60 this._byteCode
= __byteCode
.clone();
65 * Returns the byte code instructions.
67 * @return The byte code instructions.
70 public InstructionViewer
[] instructions()
72 // Use pre-cached value?
73 InstructionViewer
[] result
= this._instructions
;
75 return result
.clone();
77 // Resultant instructions
78 List
<InstructionViewer
> output
= new ArrayList
<>();
80 // Used to refer to the instructions
81 Pool pool
= this.constantPool
;
83 // We will be referencing this much!
84 byte[] byteCode
= this._byteCode
;
85 for (int at
= 0, limit
= byteCode
.length
; at
< limit
;)
87 // Setup instruction at this point
88 InstructionViewer instruction
= new RemoteInstructionViewer(
91 // Move the pointer up
92 at
+= instruction
.length();
94 // Store it for later usage
95 output
.add(instruction
);
98 // Cache for later usage
99 result
= output
.toArray(
100 new InstructionViewer
[output
.size()]);
101 this._instructions
= result
;
103 // Return all the instructions.
104 return result
.clone();
112 protected boolean internalUpdate(DebuggerState __state
)
113 throws NullPointerException