View Javadoc
1   /*
2    * Copyright (c) 2000, 2012, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20   * or visit www.oracle.com if you need additional information or have any
21   * questions.
22   *
23   */
24  
25  package sun.jvm.hotspot.code;
26  
27  import java.util.*;
28  
29  import sun.jvm.hotspot.debugger.*;
30  import sun.jvm.hotspot.runtime.VM;
31  import sun.jvm.hotspot.utilities.*;
32  import sun.jvm.hotspot.oops.Method;
33  
34  public class DebugInfoReadStream extends CompressedReadStream {
35    private NMethod code;
36    private int InvocationEntryBCI;
37    private List objectPool; // ArrayList<ObjectValue>
38  
39    public DebugInfoReadStream(NMethod code, int offset) {
40      super(code.scopesDataBegin(), offset);
41      InvocationEntryBCI = VM.getVM().getInvocationEntryBCI();
42      this.code = code;
43      this.objectPool = null;
44    }
45  
46    public DebugInfoReadStream(NMethod code, int offset, List objectPool) {
47      super(code.scopesDataBegin(), offset);
48      InvocationEntryBCI = VM.getVM().getInvocationEntryBCI();
49      this.code = code;
50      this.objectPool = objectPool;
51    }
52  
53    public OopHandle readOopHandle() {
54      return code.getOopAt(readInt());
55    }
56  
57    public Method readMethod() {
58      return code.getMethodAt(readInt());
59    }
60  
61    ScopeValue readObjectValue() {
62      int id = readInt();
63      if (Assert.ASSERTS_ENABLED) {
64        Assert.that(objectPool != null, "object pool does not exist");
65        for (Iterator itr = objectPool.iterator(); itr.hasNext();) {
66          ObjectValue ov = (ObjectValue) itr.next();
67          Assert.that(ov.id() != id, "should not be read twice");
68        }
69      }
70      ObjectValue result = new ObjectValue(id);
71      // Cache the object since an object field could reference it.
72      objectPool.add(result);
73      result.readObject(this);
74      return result;
75    }
76  
77    ScopeValue getCachedObject() {
78      int id = readInt();
79      Assert.that(objectPool != null, "object pool does not exist");
80      for (Iterator itr = objectPool.iterator(); itr.hasNext();) {
81        ObjectValue ov = (ObjectValue) itr.next();
82        if (ov.id() == id) {
83          return ov;
84        }
85      }
86      Assert.that(false, "should not reach here");
87      return null;
88    }
89  
90    public int readBCI() {
91      return readInt() + InvocationEntryBCI;
92    }
93  }