comparison agent/src/share/classes/sun/jvm/hotspot/runtime/linux_amd64/LinuxAMD64JavaThreadPDAccess.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 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.linux_amd64;
26
27 import java.io.*;
28 import java.util.*;
29 import sun.jvm.hotspot.debugger.*;
30 import sun.jvm.hotspot.debugger.amd64.*;
31 import sun.jvm.hotspot.runtime.*;
32 import sun.jvm.hotspot.runtime.amd64.*;
33 import sun.jvm.hotspot.types.*;
34 import sun.jvm.hotspot.utilities.*;
35
36 public class LinuxAMD64JavaThreadPDAccess implements JavaThreadPDAccess {
37 private static AddressField lastJavaFPField;
38 private static AddressField osThreadField;
39
40 // Field from OSThread
41 private static CIntegerField osThreadThreadIDField;
42
43 // This is currently unneeded but is being kept in case we change
44 // the currentFrameGuess algorithm
45 private static final long GUESS_SCAN_RANGE = 128 * 1024;
46
47 static {
48 VM.registerVMInitializedObserver(new Observer() {
49 public void update(Observable o, Object data) {
50 initialize(VM.getVM().getTypeDataBase());
51 }
52 });
53 }
54
55 private static synchronized void initialize(TypeDataBase db) {
56 Type type = db.lookupType("JavaThread");
57 osThreadField = type.getAddressField("_osthread");
58
59 Type anchorType = db.lookupType("JavaFrameAnchor");
60 lastJavaFPField = anchorType.getAddressField("_last_Java_fp");
61
62 Type osThreadType = db.lookupType("OSThread");
63 osThreadThreadIDField = osThreadType.getCIntegerField("_thread_id");
64 }
65
66 public Address getLastJavaFP(Address addr) {
67 return lastJavaFPField.getValue(addr.addOffsetTo(sun.jvm.hotspot.runtime.JavaThread.getAnchorField().getOffset()));
68 }
69
70 public Address getLastJavaPC(Address addr) {
71 return null;
72 }
73
74 public Address getBaseOfStackPointer(Address addr) {
75 return null;
76 }
77
78 public Frame getLastFramePD(JavaThread thread, Address addr) {
79 Address fp = thread.getLastJavaFP();
80 if (fp == null) {
81 return null; // no information
82 }
83 return new AMD64Frame(thread.getLastJavaSP(), fp);
84 }
85
86 public RegisterMap newRegisterMap(JavaThread thread, boolean updateMap) {
87 return new AMD64RegisterMap(thread, updateMap);
88 }
89
90 public Frame getCurrentFrameGuess(JavaThread thread, Address addr) {
91 ThreadProxy t = getThreadProxy(addr);
92 AMD64ThreadContext context = (AMD64ThreadContext) t.getContext();
93 AMD64CurrentFrameGuess guesser = new AMD64CurrentFrameGuess(context, thread);
94 if (!guesser.run(GUESS_SCAN_RANGE)) {
95 return null;
96 }
97 if (guesser.getPC() == null) {
98 return new AMD64Frame(guesser.getSP(), guesser.getFP());
99 } else {
100 return new AMD64Frame(guesser.getSP(), guesser.getFP(), guesser.getPC());
101 }
102 }
103
104 public void printThreadIDOn(Address addr, PrintStream tty) {
105 tty.print(getThreadProxy(addr));
106 }
107
108 public void printInfoOn(Address threadAddr, PrintStream tty) {
109 tty.print("Thread id: ");
110 printThreadIDOn(threadAddr, tty);
111 // tty.println("\nPostJavaState: " + getPostJavaState(threadAddr));
112 }
113
114 public Address getLastSP(Address addr) {
115 ThreadProxy t = getThreadProxy(addr);
116 AMD64ThreadContext context = (AMD64ThreadContext) t.getContext();
117 return context.getRegisterAsAddress(AMD64ThreadContext.RSP);
118 }
119
120 public ThreadProxy getThreadProxy(Address addr) {
121 // Addr is the address of the JavaThread.
122 // Fetch the OSThread (for now and for simplicity, not making a
123 // separate "OSThread" class in this package)
124 Address osThreadAddr = osThreadField.getValue(addr);
125 // Get the address of the _thread_id from the OSThread
126 Address threadIdAddr = osThreadAddr.addOffsetTo(osThreadThreadIDField.getOffset());
127
128 JVMDebugger debugger = VM.getVM().getDebugger();
129 return debugger.getThreadForIdentifierAddress(threadIdAddr);
130 }
131 }