hotspot/src/share/vm/ci/ciReplay.cpp
author minqi
Mon, 12 Nov 2012 14:03:53 -0800
changeset 14477 95e66ea71f71
child 14588 8ec26d2d9339
permissions -rw-r--r--
6830717: replay of compilations would help with debugging Summary: When java process crashed in compiler thread, repeat the compilation process will help finding root cause. This is done with using SA dump application class data and replay data from core dump, then use debug version of jvm to recompile the problematic java method. Reviewed-by: kvn, twisti, sspitsyn Contributed-by: yumin.qi@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
     1
/* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
     3
 *
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
     6
 * published by the Free Software Foundation.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
     7
 *
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
     8
 * This code is distributed in the hope that it will be useful, but WITHOUT
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
     9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    10
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    11
 * version 2 for more details (a copy is included in the LICENSE file that
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    12
 * accompanied this code).
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    13
 *
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License version
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    15
 * 2 along with this work; if not, write to the Free Software Foundation,
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    17
 *
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    18
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    19
 * or visit www.oracle.com if you need additional information or have any
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    20
 * questions.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    21
 *
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    22
 */
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    23
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    24
#include "precompiled.hpp"
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    25
#include "ci/ciMethodData.hpp"
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    26
#include "ci/ciReplay.hpp"
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    27
#include "ci/ciUtilities.hpp"
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    28
#include "compiler/compileBroker.hpp"
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    29
#include "memory/allocation.inline.hpp"
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    30
#include "memory/oopFactory.hpp"
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    31
#include "memory/resourceArea.hpp"
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    32
#include "utilities/copy.hpp"
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    33
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    34
#ifdef ASSERT
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    35
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    36
// ciReplay
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    37
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    38
typedef struct _ciMethodDataRecord {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    39
  const char* klass;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    40
  const char* method;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    41
  const char* signature;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    42
  int state;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    43
  int current_mileage;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    44
  intptr_t* data;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    45
  int data_length;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    46
  char* orig_data;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    47
  int orig_data_length;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    48
  int oops_length;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    49
  jobject* oops_handles;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    50
  int* oops_offsets;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    51
} ciMethodDataRecord;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    52
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    53
typedef struct _ciMethodRecord {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    54
  const char* klass;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    55
  const char* method;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    56
  const char* signature;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    57
  int instructions_size;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    58
  int interpreter_invocation_count;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    59
  int interpreter_throwout_count;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    60
  int invocation_counter;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    61
  int backedge_counter;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    62
} ciMethodRecord;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    63
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    64
class CompileReplay;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    65
static CompileReplay* replay_state;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    66
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    67
class CompileReplay : public StackObj {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    68
 private:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    69
  FILE*   stream;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    70
  Thread* thread;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    71
  Handle  protection_domain;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    72
  Handle  loader;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    73
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    74
  GrowableArray<ciMethodRecord*>     ci_method_records;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    75
  GrowableArray<ciMethodDataRecord*> ci_method_data_records;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    76
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    77
  const char* _error_message;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    78
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    79
  char* bufptr;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    80
  char* buffer;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    81
  int   buffer_length;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    82
  int   buffer_end;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    83
  int   line_no;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    84
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    85
 public:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    86
  CompileReplay(const char* filename, TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    87
    thread = THREAD;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    88
    loader = Handle(thread, SystemDictionary::java_system_loader());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    89
    stream = fopen(filename, "rt");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    90
    if (stream == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    91
      fprintf(stderr, "Can't open replay file %s\n", filename);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    92
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    93
    buffer_length = 32;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    94
    buffer = NEW_RESOURCE_ARRAY(char, buffer_length);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    95
    _error_message = NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    96
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    97
    test();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    98
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    99
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   100
  ~CompileReplay() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   101
    if (stream != NULL) fclose(stream);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   102
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   103
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   104
  void test() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   105
    strcpy(buffer, "1 2 foo 4 bar 0x9 \"this is it\"");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   106
    bufptr = buffer;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   107
    assert(parse_int("test") == 1, "what");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   108
    assert(parse_int("test") == 2, "what");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   109
    assert(strcmp(parse_string(), "foo") == 0, "what");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   110
    assert(parse_int("test") == 4, "what");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   111
    assert(strcmp(parse_string(), "bar") == 0, "what");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   112
    assert(parse_intptr_t("test") == 9, "what");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   113
    assert(strcmp(parse_quoted_string(), "this is it") == 0, "what");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   114
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   115
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   116
  bool had_error() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   117
    return _error_message != NULL || thread->has_pending_exception();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   118
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   119
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   120
  bool can_replay() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   121
    return !(stream == NULL || had_error());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   122
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   123
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   124
  void report_error(const char* msg) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   125
    _error_message = msg;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   126
    // Restore the buffer contents for error reporting
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   127
    for (int i = 0; i < buffer_end; i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   128
      if (buffer[i] == '\0') buffer[i] = ' ';
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   129
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   130
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   131
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   132
  int parse_int(const char* label) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   133
    if (had_error()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   134
      return 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   135
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   136
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   137
    int v = 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   138
    int read;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   139
    if (sscanf(bufptr, "%i%n", &v, &read) != 1) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   140
      report_error(label);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   141
    } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   142
      bufptr += read;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   143
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   144
    return v;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   145
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   146
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   147
  intptr_t parse_intptr_t(const char* label) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   148
    if (had_error()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   149
      return 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   150
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   151
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   152
    intptr_t v = 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   153
    int read;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   154
    if (sscanf(bufptr, INTPTR_FORMAT "%n", &v, &read) != 1) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   155
      report_error(label);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   156
    } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   157
      bufptr += read;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   158
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   159
    return v;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   160
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   161
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   162
  void skip_ws() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   163
    // Skip any leading whitespace
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   164
    while (*bufptr == ' ' || *bufptr == '\t') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   165
      bufptr++;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   166
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   167
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   168
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   169
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   170
  char* scan_and_terminate(char delim) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   171
    char* str = bufptr;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   172
    while (*bufptr != delim && *bufptr != '\0') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   173
      bufptr++;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   174
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   175
    if (*bufptr != '\0') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   176
      *bufptr++ = '\0';
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   177
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   178
    if (bufptr == str) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   179
      // nothing here
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   180
      return NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   181
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   182
    return str;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   183
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   184
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   185
  char* parse_string() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   186
    if (had_error()) return NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   187
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   188
    skip_ws();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   189
    return scan_and_terminate(' ');
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   190
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   191
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   192
  char* parse_quoted_string() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   193
    if (had_error()) return NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   194
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   195
    skip_ws();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   196
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   197
    if (*bufptr == '"') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   198
      bufptr++;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   199
      return scan_and_terminate('"');
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   200
    } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   201
      return scan_and_terminate(' ');
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   202
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   203
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   204
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   205
  const char* parse_escaped_string() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   206
    char* result = parse_quoted_string();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   207
    if (result != NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   208
      unescape_string(result);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   209
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   210
    return result;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   211
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   212
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   213
  // Look for the tag 'tag' followed by an
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   214
  bool parse_tag_and_count(const char* tag, int& length) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   215
    const char* t = parse_string();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   216
    if (t == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   217
      return false;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   218
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   219
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   220
    if (strcmp(tag, t) != 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   221
      report_error(tag);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   222
      return false;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   223
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   224
    length = parse_int("parse_tag_and_count");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   225
    return !had_error();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   226
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   227
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   228
  // Parse a sequence of raw data encoded as bytes and return the
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   229
  // resulting data.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   230
  char* parse_data(const char* tag, int& length) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   231
    if (!parse_tag_and_count(tag, length)) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   232
      return NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   233
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   234
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   235
    char * result = NEW_RESOURCE_ARRAY(char, length);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   236
    for (int i = 0; i < length; i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   237
      int val = parse_int("data");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   238
      result[i] = val;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   239
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   240
    return result;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   241
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   242
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   243
  // Parse a standard chunk of data emitted as:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   244
  //   'tag' <length> # # ...
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   245
  // Where each # is an intptr_t item
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   246
  intptr_t* parse_intptr_data(const char* tag, int& length) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   247
    if (!parse_tag_and_count(tag, length)) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   248
      return NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   249
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   250
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   251
    intptr_t* result = NEW_RESOURCE_ARRAY(intptr_t, length);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   252
    for (int i = 0; i < length; i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   253
      skip_ws();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   254
      intptr_t val = parse_intptr_t("data");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   255
      result[i] = val;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   256
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   257
    return result;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   258
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   259
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   260
  // Parse a possibly quoted version of a symbol into a symbolOop
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   261
  Symbol* parse_symbol(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   262
    const char* str = parse_escaped_string();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   263
    if (str != NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   264
      Symbol* sym = SymbolTable::lookup(str, (int)strlen(str), CHECK_NULL);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   265
      return sym;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   266
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   267
    return NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   268
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   269
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   270
  // Parse a valid klass name and look it up
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   271
  Klass* parse_klass(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   272
    const char* str = parse_escaped_string();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   273
    Symbol* klass_name = SymbolTable::lookup(str, (int)strlen(str), CHECK_NULL);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   274
    if (klass_name != NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   275
      Klass* k = SystemDictionary::resolve_or_fail(klass_name, loader, protection_domain, true, THREAD);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   276
      if (HAS_PENDING_EXCEPTION) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   277
        oop throwable = PENDING_EXCEPTION;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   278
        java_lang_Throwable::print(throwable, tty);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   279
        tty->cr();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   280
        report_error(str);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   281
        return NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   282
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   283
      return k;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   284
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   285
    return NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   286
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   287
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   288
  // Lookup a klass
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   289
  Klass* resolve_klass(const char* klass, TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   290
    Symbol* klass_name = SymbolTable::lookup(klass, (int)strlen(klass), CHECK_NULL);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   291
    return SystemDictionary::resolve_or_fail(klass_name, loader, protection_domain, true, CHECK_NULL);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   292
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   293
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   294
  // Parse the standard tuple of <klass> <name> <signature>
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   295
  Method* parse_method(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   296
    InstanceKlass* k = (InstanceKlass*)parse_klass(CHECK_NULL);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   297
    Symbol* method_name = parse_symbol(CHECK_NULL);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   298
    Symbol* method_signature = parse_symbol(CHECK_NULL);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   299
    Method* m = k->find_method(method_name, method_signature);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   300
    if (m == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   301
      report_error("can't find method");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   302
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   303
    return m;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   304
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   305
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   306
  // Process each line of the replay file executing each command until
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   307
  // the file ends.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   308
  void process(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   309
    line_no = 1;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   310
    int pos = 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   311
    int c = getc(stream);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   312
    while(c != EOF) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   313
      if (pos + 1 >= buffer_length) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   314
        int newl = buffer_length * 2;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   315
        char* newb = NEW_RESOURCE_ARRAY(char, newl);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   316
        memcpy(newb, buffer, pos);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   317
        buffer = newb;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   318
        buffer_length = newl;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   319
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   320
      if (c == '\n') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   321
        // null terminate it, reset the pointer and process the line
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   322
        buffer[pos] = '\0';
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   323
        buffer_end = pos++;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   324
        bufptr = buffer;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   325
        process_command(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   326
        if (had_error()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   327
          tty->print_cr("Error while parsing line %d: %s\n", line_no, _error_message);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   328
          tty->print_cr("%s", buffer);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   329
          assert(false, "error");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   330
          return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   331
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   332
        pos = 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   333
        buffer_end = 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   334
        line_no++;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   335
      } else if (c == '\r') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   336
        // skip LF
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   337
      } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   338
        buffer[pos++] = c;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   339
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   340
      c = getc(stream);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   341
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   342
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   343
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   344
  void process_command(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   345
    char* cmd = parse_string();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   346
    if (cmd == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   347
      return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   348
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   349
    if (strcmp("#", cmd) == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   350
      // ignore
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   351
    } else if (strcmp("compile", cmd) == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   352
      process_compile(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   353
    } else if (strcmp("ciMethod", cmd) == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   354
      process_ciMethod(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   355
    } else if (strcmp("ciMethodData", cmd) == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   356
      process_ciMethodData(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   357
    } else if (strcmp("staticfield", cmd) == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   358
      process_staticfield(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   359
    } else if (strcmp("ciInstanceKlass", cmd) == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   360
      process_ciInstanceKlass(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   361
    } else if (strcmp("instanceKlass", cmd) == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   362
      process_instanceKlass(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   363
#if INCLUDE_JVMTI
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   364
    } else if (strcmp("JvmtiExport", cmd) == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   365
      process_JvmtiExport(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   366
#endif // INCLUDE_JVMTI
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   367
    } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   368
      report_error("unknown command");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   369
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   370
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   371
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   372
  // compile <klass> <name> <signature> <entry_bci>
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   373
  void process_compile(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   374
    // methodHandle method;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   375
    Method* method = parse_method(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   376
    int entry_bci = parse_int("entry_bci");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   377
    Klass* k = method->method_holder();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   378
    ((InstanceKlass*)k)->initialize(THREAD);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   379
    if (HAS_PENDING_EXCEPTION) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   380
      oop throwable = PENDING_EXCEPTION;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   381
      java_lang_Throwable::print(throwable, tty);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   382
      tty->cr();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   383
      if (ReplayIgnoreInitErrors) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   384
        CLEAR_PENDING_EXCEPTION;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   385
        ((InstanceKlass*)k)->set_init_state(InstanceKlass::fully_initialized);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   386
      } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   387
        return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   388
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   389
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   390
    // Make sure the existence of a prior compile doesn't stop this one
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   391
    nmethod* nm = (entry_bci != InvocationEntryBci) ? method->lookup_osr_nmethod_for(entry_bci, CompLevel_full_optimization, true) : method->code();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   392
    if (nm != NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   393
      nm->make_not_entrant();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   394
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   395
    replay_state = this;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   396
    CompileBroker::compile_method(method, entry_bci, CompLevel_full_optimization,
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   397
                                  methodHandle(), 0, "replay", THREAD);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   398
    replay_state = NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   399
    reset();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   400
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   401
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   402
  // ciMethod <klass> <name> <signature> <invocation_counter> <backedge_counter> <interpreter_invocation_count> <interpreter_throwout_count> <instructions_size>
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   403
  //
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   404
  //
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   405
  void process_ciMethod(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   406
    Method* method = parse_method(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   407
    ciMethodRecord* rec = new_ciMethod(method);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   408
    rec->invocation_counter = parse_int("invocation_counter");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   409
    rec->backedge_counter = parse_int("backedge_counter");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   410
    rec->interpreter_invocation_count = parse_int("interpreter_invocation_count");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   411
    rec->interpreter_throwout_count = parse_int("interpreter_throwout_count");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   412
    rec->instructions_size = parse_int("instructions_size");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   413
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   414
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   415
  // ciMethodData <klass> <name> <signature> <state> <current mileage> orig <length> # # ... data <length> # # ... oops <length>
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   416
  void process_ciMethodData(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   417
    Method* method = parse_method(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   418
    /* jsut copied from Method, to build interpret data*/
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   419
    if (InstanceRefKlass::owns_pending_list_lock((JavaThread*)THREAD)) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   420
      return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   421
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   422
    // methodOopDesc::build_interpreter_method_data(method, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   423
    {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   424
      // Grab a lock here to prevent multiple
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   425
      // MethodData*s from being created.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   426
      MutexLocker ml(MethodData_lock, THREAD);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   427
      if (method->method_data() == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   428
        ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   429
        MethodData* method_data = MethodData::allocate(loader_data, method, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   430
        method->set_method_data(method_data);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   431
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   432
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   433
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   434
    // collect and record all the needed information for later
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   435
    ciMethodDataRecord* rec = new_ciMethodData(method);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   436
    rec->state = parse_int("state");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   437
    rec->current_mileage = parse_int("current_mileage");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   438
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   439
    rec->orig_data = parse_data("orig", rec->orig_data_length);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   440
    if (rec->orig_data == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   441
      return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   442
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   443
    rec->data = parse_intptr_data("data", rec->data_length);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   444
    if (rec->data == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   445
      return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   446
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   447
    if (!parse_tag_and_count("oops", rec->oops_length)) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   448
      return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   449
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   450
    rec->oops_handles = NEW_RESOURCE_ARRAY(jobject, rec->oops_length);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   451
    rec->oops_offsets = NEW_RESOURCE_ARRAY(int, rec->oops_length);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   452
    for (int i = 0; i < rec->oops_length; i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   453
      int offset = parse_int("offset");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   454
      if (had_error()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   455
        return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   456
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   457
      Klass* k = parse_klass(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   458
      rec->oops_offsets[i] = offset;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   459
      rec->oops_handles[i] = (jobject)(new KlassHandle(THREAD, k));
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   460
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   461
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   462
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   463
  // instanceKlass <name>
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   464
  //
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   465
  // Loads and initializes the klass 'name'.  This can be used to
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   466
  // create particular class loading environments
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   467
  void process_instanceKlass(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   468
    // just load the referenced class
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   469
    Klass* k = parse_klass(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   470
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   471
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   472
  // ciInstanceKlass <name> <is_linked> <is_initialized> <length> tag # # # ...
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   473
  //
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   474
  // Load the klass 'name' and link or initialize it.  Verify that the
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   475
  // constant pool is the same length as 'length' and make sure the
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   476
  // constant pool tags are in the same state.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   477
  void process_ciInstanceKlass(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   478
    InstanceKlass* k = (InstanceKlass *)parse_klass(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   479
    int is_linked = parse_int("is_linked");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   480
    int is_initialized = parse_int("is_initialized");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   481
    int length = parse_int("length");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   482
    if (is_initialized) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   483
      k->initialize(THREAD);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   484
      if (HAS_PENDING_EXCEPTION) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   485
        oop throwable = PENDING_EXCEPTION;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   486
        java_lang_Throwable::print(throwable, tty);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   487
        tty->cr();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   488
        if (ReplayIgnoreInitErrors) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   489
          CLEAR_PENDING_EXCEPTION;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   490
          k->set_init_state(InstanceKlass::fully_initialized);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   491
        } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   492
          return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   493
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   494
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   495
    } else if (is_linked) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   496
      k->link_class(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   497
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   498
    ConstantPool* cp = k->constants();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   499
    if (length != cp->length()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   500
      report_error("constant pool length mismatch: wrong class files?");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   501
      return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   502
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   503
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   504
    int parsed_two_word = 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   505
    for (int i = 1; i < length; i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   506
      int tag = parse_int("tag");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   507
      if (had_error()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   508
        return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   509
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   510
      switch (cp->tag_at(i).value()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   511
        case JVM_CONSTANT_UnresolvedClass: {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   512
          if (tag == JVM_CONSTANT_Class) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   513
            tty->print_cr("Resolving klass %s at %d", cp->unresolved_klass_at(i)->as_utf8(), i);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   514
            Klass* k = cp->klass_at(i, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   515
          }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   516
          break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   517
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   518
        case JVM_CONSTANT_Long:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   519
        case JVM_CONSTANT_Double:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   520
          parsed_two_word = i + 1;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   521
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   522
        case JVM_CONSTANT_ClassIndex:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   523
        case JVM_CONSTANT_StringIndex:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   524
        case JVM_CONSTANT_String:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   525
        case JVM_CONSTANT_UnresolvedClassInError:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   526
        case JVM_CONSTANT_Fieldref:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   527
        case JVM_CONSTANT_Methodref:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   528
        case JVM_CONSTANT_InterfaceMethodref:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   529
        case JVM_CONSTANT_NameAndType:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   530
        case JVM_CONSTANT_Utf8:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   531
        case JVM_CONSTANT_Integer:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   532
        case JVM_CONSTANT_Float:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   533
          if (tag != cp->tag_at(i).value()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   534
            report_error("tag mismatch: wrong class files?");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   535
            return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   536
          }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   537
          break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   538
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   539
        case JVM_CONSTANT_Class:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   540
          if (tag == JVM_CONSTANT_Class) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   541
          } else if (tag == JVM_CONSTANT_UnresolvedClass) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   542
            tty->print_cr("Warning: entry was unresolved in the replay data");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   543
          } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   544
            report_error("Unexpected tag");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   545
            return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   546
          }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   547
          break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   548
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   549
        case 0:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   550
          if (parsed_two_word == i) continue;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   551
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   552
        default:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   553
          ShouldNotReachHere();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   554
          break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   555
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   556
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   557
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   558
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   559
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   560
  // Initialize a class and fill in the value for a static field.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   561
  // This is useful when the compile was dependent on the value of
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   562
  // static fields but it's impossible to properly rerun the static
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   563
  // initiailizer.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   564
  void process_staticfield(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   565
    InstanceKlass* k = (InstanceKlass *)parse_klass(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   566
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   567
    if (ReplaySuppressInitializers == 0 ||
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   568
        ReplaySuppressInitializers == 2 && k->class_loader() == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   569
      return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   570
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   571
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   572
    assert(k->is_initialized(), "must be");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   573
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   574
    const char* field_name = parse_escaped_string();;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   575
    const char* field_signature = parse_string();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   576
    fieldDescriptor fd;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   577
    Symbol* name = SymbolTable::lookup(field_name, (int)strlen(field_name), CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   578
    Symbol* sig = SymbolTable::lookup(field_signature, (int)strlen(field_signature), CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   579
    if (!k->find_local_field(name, sig, &fd) ||
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   580
        !fd.is_static() ||
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   581
        fd.has_initial_value()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   582
      report_error(field_name);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   583
      return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   584
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   585
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   586
    oop java_mirror = k->java_mirror();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   587
    if (field_signature[0] == '[') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   588
      int length = parse_int("array length");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   589
      oop value = NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   590
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   591
      if (field_signature[1] == '[') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   592
        // multi dimensional array
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   593
        ArrayKlass* kelem = (ArrayKlass *)parse_klass(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   594
        int rank = 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   595
        while (field_signature[rank] == '[') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   596
          rank++;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   597
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   598
        int* dims = NEW_RESOURCE_ARRAY(int, rank);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   599
        dims[0] = length;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   600
        for (int i = 1; i < rank; i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   601
          dims[i] = 1; // These aren't relevant to the compiler
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   602
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   603
        value = kelem->multi_allocate(rank, dims, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   604
      } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   605
        if (strcmp(field_signature, "[B") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   606
          value = oopFactory::new_byteArray(length, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   607
        } else if (strcmp(field_signature, "[Z") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   608
          value = oopFactory::new_boolArray(length, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   609
        } else if (strcmp(field_signature, "[C") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   610
          value = oopFactory::new_charArray(length, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   611
        } else if (strcmp(field_signature, "[S") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   612
          value = oopFactory::new_shortArray(length, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   613
        } else if (strcmp(field_signature, "[F") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   614
          value = oopFactory::new_singleArray(length, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   615
        } else if (strcmp(field_signature, "[D") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   616
          value = oopFactory::new_doubleArray(length, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   617
        } else if (strcmp(field_signature, "[I") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   618
          value = oopFactory::new_intArray(length, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   619
        } else if (strcmp(field_signature, "[J") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   620
          value = oopFactory::new_longArray(length, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   621
        } else if (field_signature[0] == '[' && field_signature[1] == 'L') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   622
          KlassHandle kelem = resolve_klass(field_signature + 1, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   623
          value = oopFactory::new_objArray(kelem(), length, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   624
        } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   625
          report_error("unhandled array staticfield");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   626
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   627
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   628
      java_mirror->obj_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   629
    } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   630
      const char* string_value = parse_escaped_string();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   631
      if (strcmp(field_signature, "I") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   632
        int value = atoi(string_value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   633
        java_mirror->int_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   634
      } else if (strcmp(field_signature, "B") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   635
        int value = atoi(string_value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   636
        java_mirror->byte_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   637
      } else if (strcmp(field_signature, "C") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   638
        int value = atoi(string_value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   639
        java_mirror->char_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   640
      } else if (strcmp(field_signature, "S") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   641
        int value = atoi(string_value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   642
        java_mirror->short_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   643
      } else if (strcmp(field_signature, "Z") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   644
        int value = atol(string_value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   645
        java_mirror->bool_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   646
      } else if (strcmp(field_signature, "J") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   647
        jlong value;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   648
        if (sscanf(string_value, INT64_FORMAT, &value) != 1) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   649
          fprintf(stderr, "Error parsing long: %s\n", string_value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   650
          return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   651
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   652
        java_mirror->long_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   653
      } else if (strcmp(field_signature, "F") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   654
        float value = atof(string_value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   655
        java_mirror->float_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   656
      } else if (strcmp(field_signature, "D") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   657
        double value = atof(string_value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   658
        java_mirror->double_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   659
      } else if (strcmp(field_signature, "Ljava/lang/String;") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   660
        Handle value = java_lang_String::create_from_str(string_value, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   661
        java_mirror->obj_field_put(fd.offset(), value());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   662
      } else if (field_signature[0] == 'L') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   663
        Symbol* klass_name = SymbolTable::lookup(field_signature, (int)strlen(field_signature), CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   664
        KlassHandle kelem = resolve_klass(field_signature, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   665
        oop value = ((InstanceKlass*)kelem())->allocate_instance(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   666
        java_mirror->obj_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   667
      } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   668
        report_error("unhandled staticfield");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   669
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   670
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   671
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   672
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   673
#if INCLUDE_JVMTI
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   674
  void process_JvmtiExport(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   675
    const char* field = parse_string();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   676
    bool value = parse_int("JvmtiExport flag") != 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   677
    if (strcmp(field, "can_access_local_variables") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   678
      JvmtiExport::set_can_access_local_variables(value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   679
    } else if (strcmp(field, "can_hotswap_or_post_breakpoint") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   680
      JvmtiExport::set_can_hotswap_or_post_breakpoint(value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   681
    } else if (strcmp(field, "can_post_on_exceptions") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   682
      JvmtiExport::set_can_post_on_exceptions(value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   683
    } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   684
      report_error("Unrecognized JvmtiExport directive");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   685
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   686
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   687
#endif // INCLUDE_JVMTI
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   688
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   689
  // Create and initialize a record for a ciMethod
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   690
  ciMethodRecord* new_ciMethod(Method* method) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   691
    ciMethodRecord* rec = NEW_RESOURCE_OBJ(ciMethodRecord);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   692
    rec->klass =  method->method_holder()->name()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   693
    rec->method = method->name()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   694
    rec->signature = method->signature()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   695
    ci_method_records.append(rec);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   696
    return rec;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   697
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   698
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   699
  // Lookup data for a ciMethod
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   700
  ciMethodRecord* find_ciMethodRecord(Method* method) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   701
    const char* klass_name =  method->method_holder()->name()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   702
    const char* method_name = method->name()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   703
    const char* signature = method->signature()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   704
    for (int i = 0; i < ci_method_records.length(); i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   705
      ciMethodRecord* rec = ci_method_records.at(i);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   706
      if (strcmp(rec->klass, klass_name) == 0 &&
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   707
          strcmp(rec->method, method_name) == 0 &&
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   708
          strcmp(rec->signature, signature) == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   709
        return rec;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   710
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   711
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   712
    return NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   713
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   714
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   715
  // Create and initialize a record for a ciMethodData
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   716
  ciMethodDataRecord* new_ciMethodData(Method* method) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   717
    ciMethodDataRecord* rec = NEW_RESOURCE_OBJ(ciMethodDataRecord);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   718
    rec->klass =  method->method_holder()->name()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   719
    rec->method = method->name()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   720
    rec->signature = method->signature()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   721
    ci_method_data_records.append(rec);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   722
    return rec;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   723
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   724
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   725
  // Lookup data for a ciMethodData
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   726
  ciMethodDataRecord* find_ciMethodDataRecord(Method* method) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   727
    const char* klass_name =  method->method_holder()->name()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   728
    const char* method_name = method->name()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   729
    const char* signature = method->signature()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   730
    for (int i = 0; i < ci_method_data_records.length(); i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   731
      ciMethodDataRecord* rec = ci_method_data_records.at(i);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   732
      if (strcmp(rec->klass, klass_name) == 0 &&
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   733
          strcmp(rec->method, method_name) == 0 &&
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   734
          strcmp(rec->signature, signature) == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   735
        return rec;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   736
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   737
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   738
    return NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   739
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   740
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   741
  const char* error_message() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   742
    return _error_message;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   743
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   744
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   745
  void reset() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   746
    _error_message = NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   747
    ci_method_records.clear();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   748
    ci_method_data_records.clear();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   749
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   750
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   751
  // Take an ascii string contain \u#### escapes and convert it to utf8
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   752
  // in place.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   753
  static void unescape_string(char* value) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   754
    char* from = value;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   755
    char* to = value;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   756
    while (*from != '\0') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   757
      if (*from != '\\') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   758
        *from++ = *to++;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   759
      } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   760
        switch (from[1]) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   761
          case 'u': {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   762
            from += 2;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   763
            jchar value=0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   764
            for (int i=0; i<4; i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   765
              char c = *from++;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   766
              switch (c) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   767
                case '0': case '1': case '2': case '3': case '4':
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   768
                case '5': case '6': case '7': case '8': case '9':
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   769
                  value = (value << 4) + c - '0';
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   770
                  break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   771
                case 'a': case 'b': case 'c':
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   772
                case 'd': case 'e': case 'f':
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   773
                  value = (value << 4) + 10 + c - 'a';
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   774
                  break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   775
                case 'A': case 'B': case 'C':
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   776
                case 'D': case 'E': case 'F':
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   777
                  value = (value << 4) + 10 + c - 'A';
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   778
                  break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   779
                default:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   780
                  ShouldNotReachHere();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   781
              }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   782
            }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   783
            UNICODE::convert_to_utf8(&value, 1, to);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   784
            to++;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   785
            break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   786
          }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   787
          case 't': *to++ = '\t'; from += 2; break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   788
          case 'n': *to++ = '\n'; from += 2; break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   789
          case 'r': *to++ = '\r'; from += 2; break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   790
          case 'f': *to++ = '\f'; from += 2; break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   791
          default:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   792
            ShouldNotReachHere();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   793
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   794
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   795
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   796
    *from = *to;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   797
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   798
};
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   799
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   800
void ciReplay::replay(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   801
  int exit_code = replay_impl(THREAD);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   802
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   803
  Threads::destroy_vm();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   804
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   805
  vm_exit(exit_code);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   806
}
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   807
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   808
int ciReplay::replay_impl(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   809
  HandleMark hm;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   810
  ResourceMark rm;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   811
  // Make sure we don't run with background compilation
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   812
  BackgroundCompilation = false;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   813
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   814
  if (ReplaySuppressInitializers > 2) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   815
    // ReplaySuppressInitializers > 2 means that we want to allow
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   816
    // normal VM bootstrap but once we get into the replay itself
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   817
    // don't allow any intializers to be run.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   818
    ReplaySuppressInitializers = 1;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   819
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   820
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   821
  // Load and parse the replay data
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   822
  CompileReplay rp(ReplayDataFile, THREAD);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   823
  int exit_code = 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   824
  if (rp.can_replay()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   825
    rp.process(THREAD);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   826
  } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   827
    exit_code = 1;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   828
    return exit_code;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   829
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   830
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   831
  if (HAS_PENDING_EXCEPTION) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   832
    oop throwable = PENDING_EXCEPTION;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   833
    CLEAR_PENDING_EXCEPTION;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   834
    java_lang_Throwable::print(throwable, tty);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   835
    tty->cr();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   836
    java_lang_Throwable::print_stack_trace(throwable, tty);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   837
    tty->cr();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   838
    exit_code = 2;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   839
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   840
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   841
  if (rp.had_error()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   842
    tty->print_cr("Failed on %s", rp.error_message());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   843
    exit_code = 1;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   844
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   845
  return exit_code;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   846
}
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   847
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   848
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   849
void ciReplay::initialize(ciMethodData* m) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   850
  if (replay_state == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   851
    return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   852
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   853
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   854
  ASSERT_IN_VM;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   855
  ResourceMark rm;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   856
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   857
  Method* method = m->get_MethodData()->method();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   858
  ciMethodDataRecord* rec = replay_state->find_ciMethodDataRecord(method);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   859
  if (rec == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   860
    // This indicates some mismatch with the original environment and
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   861
    // the replay environment though it's not always enough to
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   862
    // interfere with reproducing a bug
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   863
    tty->print_cr("Warning: requesting ciMethodData record for method with no data: ");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   864
    method->print_name(tty);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   865
    tty->cr();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   866
  } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   867
    m->_state = rec->state;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   868
    m->_current_mileage = rec->current_mileage;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   869
    if (rec->data_length != 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   870
      assert(m->_data_size == rec->data_length * (int)sizeof(rec->data[0]), "must agree");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   871
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   872
      // Write the correct ciObjects back into the profile data
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   873
      ciEnv* env = ciEnv::current();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   874
      for (int i = 0; i < rec->oops_length; i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   875
        KlassHandle *h = (KlassHandle *)rec->oops_handles[i];
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   876
        *(ciMetadata**)(rec->data + rec->oops_offsets[i]) =
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   877
          env->get_metadata((*h)());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   878
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   879
      // Copy the updated profile data into place as intptr_ts
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   880
#ifdef _LP64
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   881
      Copy::conjoint_jlongs_atomic((jlong *)rec->data, (jlong *)m->_data, rec->data_length);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   882
#else
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   883
      Copy::conjoint_jints_atomic((jint *)rec->data, (jint *)m->_data, rec->data_length);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   884
#endif
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   885
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   886
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   887
    // copy in the original header
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   888
    Copy::conjoint_jbytes(rec->orig_data, (char*)&m->_orig, rec->orig_data_length);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   889
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   890
}
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   891
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   892
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   893
bool ciReplay::should_not_inline(ciMethod* method) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   894
  if (replay_state == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   895
    return false;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   896
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   897
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   898
  VM_ENTRY_MARK;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   899
  // ciMethod without a record shouldn't be inlined.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   900
  return replay_state->find_ciMethodRecord(method->get_Method()) == NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   901
}
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   902
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   903
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   904
void ciReplay::initialize(ciMethod* m) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   905
  if (replay_state == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   906
    return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   907
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   908
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   909
  ASSERT_IN_VM;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   910
  ResourceMark rm;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   911
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   912
  Method* method = m->get_Method();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   913
  ciMethodRecord* rec = replay_state->find_ciMethodRecord(method);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   914
  if (rec == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   915
    // This indicates some mismatch with the original environment and
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   916
    // the replay environment though it's not always enough to
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   917
    // interfere with reproducing a bug
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   918
    tty->print_cr("Warning: requesting ciMethod record for method with no data: ");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   919
    method->print_name(tty);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   920
    tty->cr();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   921
  } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   922
    // m->_instructions_size = rec->instructions_size;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   923
    m->_instructions_size = -1;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   924
    m->_interpreter_invocation_count = rec->interpreter_invocation_count;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   925
    m->_interpreter_throwout_count = rec->interpreter_throwout_count;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   926
    method->invocation_counter()->_counter = rec->invocation_counter;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   927
    method->backedge_counter()->_counter = rec->backedge_counter;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   928
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   929
}
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   930
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   931
bool ciReplay::is_loaded(Method* method) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   932
  if (replay_state == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   933
    return true;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   934
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   935
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   936
  ASSERT_IN_VM;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   937
  ResourceMark rm;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   938
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   939
  ciMethodRecord* rec = replay_state->find_ciMethodRecord(method);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   940
  return rec != NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   941
}
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   942
#endif