comparison agent/src/share/classes/sun/jvm/hotspot/runtime/solaris_x86/SolarisX86JavaThreadPDAccess.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c18cbe5936b8
comparison
equal deleted inserted replaced
-1:000000000000 0:a61af66fc99e
1 /*
2 * Copyright 2000-2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 package sun.jvm.hotspot.runtime.solaris_x86;
26
27 import java.io.*;
28 import java.util.*;
29 import sun.jvm.hotspot.debugger.*;
30 import sun.jvm.hotspot.debugger.x86.*;
31 import sun.jvm.hotspot.runtime.*;
32 import sun.jvm.hotspot.runtime.x86.*;
33 import sun.jvm.hotspot.types.*;
34 import sun.jvm.hotspot.utilities.*;
35
36 /** Placeholder for now to allow us to start the SA without support
37 for stack traces */
38
39 public class SolarisX86JavaThreadPDAccess implements JavaThreadPDAccess {
40 private static AddressField lastJavaFPField;
41 private static AddressField osThreadField;
42 private static AddressField baseOfStackPointerField;
43
44 // Field from OSThread
45 private static CIntegerField osThreadThreadIDField;
46
47 // This is currently unneeded but is being kept in case we change
48 // the currentFrameGuess algorithm
49 private static final long GUESS_SCAN_RANGE = 128 * 1024;
50
51
52 static {
53 VM.registerVMInitializedObserver(new Observer() {
54 public void update(Observable o, Object data) {
55 initialize(VM.getVM().getTypeDataBase());
56 }
57 });
58 }
59
60 private static synchronized void initialize(TypeDataBase db) {
61 Type type = db.lookupType("JavaThread");
62 Type anchorType = db.lookupType("JavaFrameAnchor");
63
64 lastJavaFPField = anchorType.getAddressField("_last_Java_fp");
65 osThreadField = type.getAddressField("_osthread");
66
67 type = db.lookupType("OSThread");
68 osThreadThreadIDField = type.getCIntegerField("_thread_id");
69 }
70
71 public Address getLastJavaFP(Address addr) {
72 return lastJavaFPField.getValue(addr.addOffsetTo(sun.jvm.hotspot.runtime.JavaThread.getAnchorField().getOffset()));
73 }
74
75 public Address getLastJavaPC(Address addr) {
76 return null;
77 }
78
79 public Address getBaseOfStackPointer(Address addr) {
80 return null;
81 }
82
83 public Frame getLastFramePD(JavaThread thread, Address addr) {
84 Address fp = thread.getLastJavaFP();
85 if (fp == null) {
86 return null; // no information
87 }
88 Address pc = thread.getLastJavaPC();
89 if ( pc != null ) {
90 return new X86Frame(thread.getLastJavaSP(), fp, pc);
91 } else {
92 return new X86Frame(thread.getLastJavaSP(), fp);
93 }
94 }
95
96 public RegisterMap newRegisterMap(JavaThread thread, boolean updateMap) {
97 return new X86RegisterMap(thread, updateMap);
98 }
99
100 public Frame getCurrentFrameGuess(JavaThread thread, Address addr) {
101 ThreadProxy t = getThreadProxy(addr);
102 X86ThreadContext context = (X86ThreadContext) t.getContext();
103 X86CurrentFrameGuess guesser = new X86CurrentFrameGuess(context, thread);
104 if (!guesser.run(GUESS_SCAN_RANGE)) {
105 return null;
106 }
107 if (guesser.getPC() == null) {
108 return new X86Frame(guesser.getSP(), guesser.getFP());
109 } else {
110 return new X86Frame(guesser.getSP(), guesser.getFP(), guesser.getPC());
111 }
112 }
113
114
115 public void printThreadIDOn(Address addr, PrintStream tty) {
116 tty.print(getThreadProxy(addr));
117 }
118
119
120 public void printInfoOn(Address threadAddr, PrintStream tty) {
121 }
122
123 public Address getLastSP(Address addr) {
124 ThreadProxy t = getThreadProxy(addr);
125 X86ThreadContext context = (X86ThreadContext) t.getContext();
126 return context.getRegisterAsAddress(X86ThreadContext.ESP);
127 }
128
129 public ThreadProxy getThreadProxy(Address addr) {
130 // Fetch the OSThread (for now and for simplicity, not making a
131 // separate "OSThread" class in this package)
132 Address osThreadAddr = osThreadField.getValue(addr);
133 // Get the address of the thread ID from the OSThread
134 Address tidAddr = osThreadAddr.addOffsetTo(osThreadThreadIDField.getOffset());
135
136 JVMDebugger debugger = VM.getVM().getDebugger();
137 return debugger.getThreadForIdentifierAddress(tidAddr);
138 }
139
140 }