sharkStateScanner.cpp revision 1879:f95d63e2154a
1107120Sjulian/*
2107120Sjulian * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
3139823Simp * Copyright 2008, 2009 Red Hat, Inc.
4139823Simp * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5139823Simp *
6107120Sjulian * This code is free software; you can redistribute it and/or modify it
7107120Sjulian * under the terms of the GNU General Public License version 2 only, as
8107120Sjulian * published by the Free Software Foundation.
9107120Sjulian *
10107120Sjulian * This code is distributed in the hope that it will be useful, but WITHOUT
11107120Sjulian * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12107120Sjulian * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13107120Sjulian * version 2 for more details (a copy is included in the LICENSE file that
14107120Sjulian * accompanied this code).
15107120Sjulian *
16107120Sjulian * You should have received a copy of the GNU General Public License version
17107120Sjulian * 2 along with this work; if not, write to the Free Software Foundation,
18107120Sjulian * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19107120Sjulian *
20107120Sjulian * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21107120Sjulian * or visit www.oracle.com if you need additional information or have any
22107120Sjulian * questions.
23107120Sjulian *
24107120Sjulian */
25107120Sjulian
26107120Sjulian#include "precompiled.hpp"
27107120Sjulian#include "shark/sharkState.hpp"
28107120Sjulian#include "shark/sharkStateScanner.hpp"
29107120Sjulian
30114878Sjulianusing namespace llvm;
31107120Sjulian
32107120Sjulianvoid SharkStateScanner::scan(SharkState* state) {
33107120Sjulian  start_frame();
34107120Sjulian
35107120Sjulian  // Expression stack
36107120Sjulian  stack_integrity_checks(state);
37107120Sjulian  start_stack(state->stack_depth());
38107120Sjulian  for (int i = state->stack_depth() - 1; i >= 0; i--) {
39107120Sjulian    process_stack_slot(
40107120Sjulian      i,
41107120Sjulian      state->stack_addr(i),
42107120Sjulian      stack()->stack_slots_offset() +
43107120Sjulian        i + max_stack() - state->stack_depth());
44107120Sjulian  }
45107120Sjulian  end_stack();
46107120Sjulian
47107120Sjulian  // Monitors
48107120Sjulian  start_monitors(state->num_monitors());
49107120Sjulian  for (int i = 0; i < state->num_monitors(); i++) {
50107120Sjulian    process_monitor(
51107120Sjulian      i,
52107120Sjulian      stack()->monitor_offset(i),
53107120Sjulian      stack()->monitor_object_offset(i));
54107120Sjulian  }
55107120Sjulian  end_monitors();
56107120Sjulian
57107120Sjulian  // Frame header
58107120Sjulian  start_frame_header();
59107120Sjulian  process_oop_tmp_slot(
60107120Sjulian    state->oop_tmp_addr(), stack()->oop_tmp_slot_offset());
61107120Sjulian  process_method_slot(state->method_addr(), stack()->method_slot_offset());
62107120Sjulian  process_pc_slot(stack()->pc_slot_offset());
63107120Sjulian  end_frame_header();
64107120Sjulian
65107120Sjulian  // Local variables
66107120Sjulian  locals_integrity_checks(state);
67107120Sjulian  start_locals();
68107120Sjulian  for (int i = 0; i < max_locals(); i++) {
69107120Sjulian    process_local_slot(
70107120Sjulian      i,
71107120Sjulian      state->local_addr(i),
72107120Sjulian      stack()->locals_slots_offset() + max_locals() - 1 - i);
73107120Sjulian  }
74107120Sjulian  end_locals();
75107120Sjulian
76107120Sjulian  end_frame();
77107120Sjulian}
78107120Sjulian
79107120Sjulian#ifndef PRODUCT
80107120Sjulianvoid SharkStateScanner::stack_integrity_checks(SharkState* state) {
81107120Sjulian  for (int i = 0; i < state->stack_depth(); i++) {
82107120Sjulian    if (state->stack(i)) {
83107120Sjulian      if (state->stack(i)->is_two_word())
84107120Sjulian        assert(state->stack(i - 1) == NULL, "should be");
85107120Sjulian    }
86107120Sjulian    else {
87107120Sjulian      assert(state->stack(i + 1)->is_two_word(), "should be");
88107120Sjulian    }
89107120Sjulian  }
90107120Sjulian}
91107120Sjulian
92107120Sjulianvoid SharkStateScanner::locals_integrity_checks(SharkState* state) {
93107120Sjulian  for (int i = 0; i < max_locals(); i++) {
94107120Sjulian    if (state->local(i)) {
95107120Sjulian      if (state->local(i)->is_two_word())
96107120Sjulian        assert(state->local(i + 1) == NULL, "should be");
97107120Sjulian    }
98107120Sjulian  }
99107120Sjulian}
100107120Sjulian#endif // !PRODUCT
101107120Sjulian