hotspot/src/share/vm/ci/ciReplay.cpp
author minqi
Fri, 19 Jul 2013 14:43:45 -0700
changeset 18984 a0fce9081603
parent 17376 4ee999c3c007
child 20695 4f5a5e95090b
permissions -rw-r--r--
8012263: ciReplay: gracefully exit & report meaningful error when replay data parsing fails Summary: find_method could return NULL so need explicitly check if there is error after parse_method, exit on error to avoid crash. Reviewed-by: kvn, twisti Contributed-by: yumin.qi@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15228
e92acc84ade3 7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents: 14588
diff changeset
     1
/* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
14477
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"
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14588
diff changeset
    33
#include "utilities/macros.hpp"
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    34
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14477
diff changeset
    35
#ifndef PRODUCT
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    36
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    37
// ciReplay
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    38
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    39
typedef struct _ciMethodDataRecord {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    40
  const char* klass;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    41
  const char* method;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    42
  const char* signature;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    43
  int state;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    44
  int current_mileage;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    45
  intptr_t* data;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    46
  int data_length;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    47
  char* orig_data;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    48
  int orig_data_length;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    49
  int oops_length;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    50
  jobject* oops_handles;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    51
  int* oops_offsets;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    52
} ciMethodDataRecord;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    53
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    54
typedef struct _ciMethodRecord {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    55
  const char* klass;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    56
  const char* method;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    57
  const char* signature;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    58
  int instructions_size;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    59
  int interpreter_invocation_count;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    60
  int interpreter_throwout_count;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    61
  int invocation_counter;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    62
  int backedge_counter;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    63
} ciMethodRecord;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    64
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    65
class CompileReplay;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    66
static CompileReplay* replay_state;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    67
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    68
class CompileReplay : public StackObj {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    69
 private:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    70
  FILE*   stream;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    71
  Thread* thread;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    72
  Handle  protection_domain;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    73
  Handle  loader;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    74
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    75
  GrowableArray<ciMethodRecord*>     ci_method_records;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    76
  GrowableArray<ciMethodDataRecord*> ci_method_data_records;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    77
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    78
  const char* _error_message;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    79
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    80
  char* bufptr;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    81
  char* buffer;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    82
  int   buffer_length;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    83
  int   buffer_end;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    84
  int   line_no;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    85
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    86
 public:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    87
  CompileReplay(const char* filename, TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    88
    thread = THREAD;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    89
    loader = Handle(thread, SystemDictionary::java_system_loader());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    90
    stream = fopen(filename, "rt");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    91
    if (stream == NULL) {
17121
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 17000
diff changeset
    92
      fprintf(stderr, "ERROR: Can't open replay file %s\n", filename);
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    93
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    94
    buffer_length = 32;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    95
    buffer = NEW_RESOURCE_ARRAY(char, buffer_length);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    96
    _error_message = NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    97
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
    98
    test();
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   101
  ~CompileReplay() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   102
    if (stream != NULL) fclose(stream);
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   105
  void test() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   106
    strcpy(buffer, "1 2 foo 4 bar 0x9 \"this is it\"");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   107
    bufptr = buffer;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   108
    assert(parse_int("test") == 1, "what");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   109
    assert(parse_int("test") == 2, "what");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   110
    assert(strcmp(parse_string(), "foo") == 0, "what");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   111
    assert(parse_int("test") == 4, "what");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   112
    assert(strcmp(parse_string(), "bar") == 0, "what");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   113
    assert(parse_intptr_t("test") == 9, "what");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   114
    assert(strcmp(parse_quoted_string(), "this is it") == 0, "what");
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   117
  bool had_error() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   118
    return _error_message != NULL || thread->has_pending_exception();
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   121
  bool can_replay() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   122
    return !(stream == NULL || had_error());
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   125
  void report_error(const char* msg) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   126
    _error_message = msg;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   127
    // Restore the buffer contents for error reporting
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   128
    for (int i = 0; i < buffer_end; i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   129
      if (buffer[i] == '\0') buffer[i] = ' ';
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   133
  int parse_int(const char* label) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   134
    if (had_error()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   135
      return 0;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   138
    int v = 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   139
    int read;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   140
    if (sscanf(bufptr, "%i%n", &v, &read) != 1) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   141
      report_error(label);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   142
    } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   143
      bufptr += read;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   144
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   145
    return v;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   148
  intptr_t parse_intptr_t(const char* label) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   149
    if (had_error()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   150
      return 0;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   153
    intptr_t v = 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   154
    int read;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   155
    if (sscanf(bufptr, INTPTR_FORMAT "%n", &v, &read) != 1) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   156
      report_error(label);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   157
    } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   158
      bufptr += read;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   159
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   160
    return v;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   163
  void skip_ws() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   164
    // Skip any leading whitespace
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   165
    while (*bufptr == ' ' || *bufptr == '\t') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   166
      bufptr++;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   171
  char* scan_and_terminate(char delim) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   172
    char* str = bufptr;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   173
    while (*bufptr != delim && *bufptr != '\0') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   174
      bufptr++;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   175
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   176
    if (*bufptr != '\0') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   177
      *bufptr++ = '\0';
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   178
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   179
    if (bufptr == str) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   180
      // nothing here
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   181
      return NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   182
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   183
    return str;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   186
  char* parse_string() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   187
    if (had_error()) return NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   188
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   189
    skip_ws();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   190
    return scan_and_terminate(' ');
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   193
  char* parse_quoted_string() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   194
    if (had_error()) return NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   195
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   196
    skip_ws();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   197
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   198
    if (*bufptr == '"') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   199
      bufptr++;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   200
      return scan_and_terminate('"');
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   201
    } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   202
      return scan_and_terminate(' ');
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   206
  const char* parse_escaped_string() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   207
    char* result = parse_quoted_string();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   208
    if (result != NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   209
      unescape_string(result);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   210
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   211
    return result;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   214
  // Look for the tag 'tag' followed by an
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   215
  bool parse_tag_and_count(const char* tag, int& length) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   216
    const char* t = parse_string();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   217
    if (t == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   218
      return false;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   221
    if (strcmp(tag, t) != 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   222
      report_error(tag);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   223
      return false;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   224
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   225
    length = parse_int("parse_tag_and_count");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   226
    return !had_error();
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   229
  // 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
   230
  // resulting data.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   231
  char* parse_data(const char* tag, int& length) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   232
    if (!parse_tag_and_count(tag, length)) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   233
      return NULL;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   236
    char * result = NEW_RESOURCE_ARRAY(char, length);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   237
    for (int i = 0; i < length; i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   238
      int val = parse_int("data");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   239
      result[i] = val;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   240
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   241
    return result;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   244
  // Parse a standard chunk of data emitted as:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   245
  //   'tag' <length> # # ...
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   246
  // Where each # is an intptr_t item
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   247
  intptr_t* parse_intptr_data(const char* tag, int& length) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   248
    if (!parse_tag_and_count(tag, length)) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   249
      return NULL;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   252
    intptr_t* result = NEW_RESOURCE_ARRAY(intptr_t, length);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   253
    for (int i = 0; i < length; i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   254
      skip_ws();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   255
      intptr_t val = parse_intptr_t("data");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   256
      result[i] = val;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   257
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   258
    return result;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   261
  // Parse a possibly quoted version of a symbol into a symbolOop
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   262
  Symbol* parse_symbol(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   263
    const char* str = parse_escaped_string();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   264
    if (str != NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   265
      Symbol* sym = SymbolTable::lookup(str, (int)strlen(str), CHECK_NULL);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   266
      return sym;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   267
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   268
    return NULL;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   271
  // Parse a valid klass name and look it up
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   272
  Klass* parse_klass(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   273
    const char* str = parse_escaped_string();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   274
    Symbol* klass_name = SymbolTable::lookup(str, (int)strlen(str), CHECK_NULL);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   275
    if (klass_name != NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   276
      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
   277
      if (HAS_PENDING_EXCEPTION) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   278
        oop throwable = PENDING_EXCEPTION;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   279
        java_lang_Throwable::print(throwable, tty);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   280
        tty->cr();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   281
        report_error(str);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   282
        return NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   283
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   284
      return k;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   285
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   286
    return NULL;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   289
  // Lookup a klass
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   290
  Klass* resolve_klass(const char* klass, TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   291
    Symbol* klass_name = SymbolTable::lookup(klass, (int)strlen(klass), CHECK_NULL);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   292
    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
   293
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   294
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   295
  // Parse the standard tuple of <klass> <name> <signature>
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   296
  Method* parse_method(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   297
    InstanceKlass* k = (InstanceKlass*)parse_klass(CHECK_NULL);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   298
    Symbol* method_name = parse_symbol(CHECK_NULL);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   299
    Symbol* method_signature = parse_symbol(CHECK_NULL);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   300
    Method* m = k->find_method(method_name, method_signature);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   301
    if (m == NULL) {
18984
a0fce9081603 8012263: ciReplay: gracefully exit & report meaningful error when replay data parsing fails
minqi
parents: 17376
diff changeset
   302
      report_error("Can't find method");
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   303
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   304
    return m;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   307
  // Process each line of the replay file executing each command until
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   308
  // the file ends.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   309
  void process(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   310
    line_no = 1;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   311
    int pos = 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   312
    int c = getc(stream);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   313
    while(c != EOF) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   314
      if (pos + 1 >= buffer_length) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   315
        int newl = buffer_length * 2;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   316
        char* newb = NEW_RESOURCE_ARRAY(char, newl);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   317
        memcpy(newb, buffer, pos);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   318
        buffer = newb;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   319
        buffer_length = newl;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   320
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   321
      if (c == '\n') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   322
        // null terminate it, reset the pointer and process the line
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   323
        buffer[pos] = '\0';
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   324
        buffer_end = pos++;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   325
        bufptr = buffer;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   326
        process_command(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   327
        if (had_error()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   328
          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
   329
          tty->print_cr("%s", buffer);
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
17123
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   372
  // validation of comp_level
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   373
  bool is_valid_comp_level(int comp_level) {
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   374
    const int msg_len = 256;
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   375
    char* msg = NULL;
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   376
    if (!is_compile(comp_level)) {
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   377
      msg = NEW_RESOURCE_ARRAY(char, msg_len);
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   378
      jio_snprintf(msg, msg_len, "%d isn't compilation level", comp_level);
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   379
    } else if (!TieredCompilation && (comp_level != CompLevel_highest_tier)) {
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   380
      msg = NEW_RESOURCE_ARRAY(char, msg_len);
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   381
      switch (comp_level) {
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   382
        case CompLevel_simple:
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   383
          jio_snprintf(msg, msg_len, "compilation level %d requires Client VM or TieredCompilation", comp_level);
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   384
          break;
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   385
        case CompLevel_full_optimization:
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   386
          jio_snprintf(msg, msg_len, "compilation level %d requires Server VM", comp_level);
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   387
          break;
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   388
        default:
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   389
          jio_snprintf(msg, msg_len, "compilation level %d requires TieredCompilation", comp_level);
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   390
      }
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   391
    }
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   392
    if (msg != NULL) {
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   393
      report_error(msg);
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   394
      return false;
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   395
    }
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   396
    return true;
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   397
  }
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   398
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   399
  // compile <klass> <name> <signature> <entry_bci> <comp_level>
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   400
  void process_compile(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   401
    Method* method = parse_method(CHECK);
18984
a0fce9081603 8012263: ciReplay: gracefully exit & report meaningful error when replay data parsing fails
minqi
parents: 17376
diff changeset
   402
    if (had_error()) return;
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   403
    int entry_bci = parse_int("entry_bci");
17123
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   404
    const char* comp_level_label = "comp_level";
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   405
    int comp_level = parse_int(comp_level_label);
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   406
    // old version w/o comp_level
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   407
    if (had_error() && (error_message() == comp_level_label)) {
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   408
      comp_level = CompLevel_full_optimization;
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   409
    }
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   410
    if (!is_valid_comp_level(comp_level)) {
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   411
      return;
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   412
    }
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   413
    Klass* k = method->method_holder();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   414
    ((InstanceKlass*)k)->initialize(THREAD);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   415
    if (HAS_PENDING_EXCEPTION) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   416
      oop throwable = PENDING_EXCEPTION;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   417
      java_lang_Throwable::print(throwable, tty);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   418
      tty->cr();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   419
      if (ReplayIgnoreInitErrors) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   420
        CLEAR_PENDING_EXCEPTION;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   421
        ((InstanceKlass*)k)->set_init_state(InstanceKlass::fully_initialized);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   422
      } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   423
        return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   424
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   425
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   426
    // Make sure the existence of a prior compile doesn't stop this one
17123
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   427
    nmethod* nm = (entry_bci != InvocationEntryBci) ? method->lookup_osr_nmethod_for(entry_bci, comp_level, true) : method->code();
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   428
    if (nm != NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   429
      nm->make_not_entrant();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   430
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   431
    replay_state = this;
17123
a8e62eed2e3e 8011675: adding compilation level to replay data
iignatyev
parents: 17121
diff changeset
   432
    CompileBroker::compile_method(method, entry_bci, comp_level,
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   433
                                  methodHandle(), 0, "replay", THREAD);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   434
    replay_state = NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   435
    reset();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   436
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   437
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   438
  // 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
   439
  //
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   440
  //
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   441
  void process_ciMethod(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   442
    Method* method = parse_method(CHECK);
18984
a0fce9081603 8012263: ciReplay: gracefully exit & report meaningful error when replay data parsing fails
minqi
parents: 17376
diff changeset
   443
    if (had_error()) return;
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   444
    ciMethodRecord* rec = new_ciMethod(method);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   445
    rec->invocation_counter = parse_int("invocation_counter");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   446
    rec->backedge_counter = parse_int("backedge_counter");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   447
    rec->interpreter_invocation_count = parse_int("interpreter_invocation_count");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   448
    rec->interpreter_throwout_count = parse_int("interpreter_throwout_count");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   449
    rec->instructions_size = parse_int("instructions_size");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   450
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   451
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   452
  // 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
   453
  void process_ciMethodData(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   454
    Method* method = parse_method(CHECK);
18984
a0fce9081603 8012263: ciReplay: gracefully exit & report meaningful error when replay data parsing fails
minqi
parents: 17376
diff changeset
   455
    if (had_error()) return;
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   456
    /* jsut copied from Method, to build interpret data*/
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   457
    if (InstanceRefKlass::owns_pending_list_lock((JavaThread*)THREAD)) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   458
      return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   459
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   460
    // methodOopDesc::build_interpreter_method_data(method, CHECK);
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
      // Grab a lock here to prevent multiple
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   463
      // MethodData*s from being created.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   464
      MutexLocker ml(MethodData_lock, THREAD);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   465
      if (method->method_data() == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   466
        ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   467
        MethodData* method_data = MethodData::allocate(loader_data, method, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   468
        method->set_method_data(method_data);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   469
      }
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
    // collect and record all the needed information for later
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   473
    ciMethodDataRecord* rec = new_ciMethodData(method);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   474
    rec->state = parse_int("state");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   475
    rec->current_mileage = parse_int("current_mileage");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   476
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   477
    rec->orig_data = parse_data("orig", rec->orig_data_length);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   478
    if (rec->orig_data == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   479
      return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   480
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   481
    rec->data = parse_intptr_data("data", rec->data_length);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   482
    if (rec->data == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   483
      return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   484
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   485
    if (!parse_tag_and_count("oops", rec->oops_length)) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   486
      return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   487
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   488
    rec->oops_handles = NEW_RESOURCE_ARRAY(jobject, rec->oops_length);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   489
    rec->oops_offsets = NEW_RESOURCE_ARRAY(int, rec->oops_length);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   490
    for (int i = 0; i < rec->oops_length; i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   491
      int offset = parse_int("offset");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   492
      if (had_error()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   493
        return;
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
      Klass* k = parse_klass(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   496
      rec->oops_offsets[i] = offset;
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17123
diff changeset
   497
      KlassHandle *kh = NEW_C_HEAP_OBJ(KlassHandle, mtCompiler);
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17123
diff changeset
   498
      ::new ((void*)kh) KlassHandle(THREAD, k);
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17123
diff changeset
   499
      rec->oops_handles[i] = (jobject)kh;
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   500
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   501
  }
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
  // instanceKlass <name>
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   504
  //
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   505
  // Loads and initializes the klass 'name'.  This can be used to
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   506
  // create particular class loading environments
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   507
  void process_instanceKlass(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   508
    // just load the referenced class
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   509
    Klass* k = parse_klass(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   510
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   511
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   512
  // ciInstanceKlass <name> <is_linked> <is_initialized> <length> tag # # # ...
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   513
  //
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   514
  // 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
   515
  // 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
   516
  // constant pool tags are in the same state.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   517
  void process_ciInstanceKlass(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   518
    InstanceKlass* k = (InstanceKlass *)parse_klass(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   519
    int is_linked = parse_int("is_linked");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   520
    int is_initialized = parse_int("is_initialized");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   521
    int length = parse_int("length");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   522
    if (is_initialized) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   523
      k->initialize(THREAD);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   524
      if (HAS_PENDING_EXCEPTION) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   525
        oop throwable = PENDING_EXCEPTION;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   526
        java_lang_Throwable::print(throwable, tty);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   527
        tty->cr();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   528
        if (ReplayIgnoreInitErrors) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   529
          CLEAR_PENDING_EXCEPTION;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   530
          k->set_init_state(InstanceKlass::fully_initialized);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   531
        } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   532
          return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   533
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   534
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   535
    } else if (is_linked) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   536
      k->link_class(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   537
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   538
    ConstantPool* cp = k->constants();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   539
    if (length != cp->length()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   540
      report_error("constant pool length mismatch: wrong class files?");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   541
      return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   542
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   543
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   544
    int parsed_two_word = 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   545
    for (int i = 1; i < length; i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   546
      int tag = parse_int("tag");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   547
      if (had_error()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   548
        return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   549
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   550
      switch (cp->tag_at(i).value()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   551
        case JVM_CONSTANT_UnresolvedClass: {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   552
          if (tag == JVM_CONSTANT_Class) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   553
            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
   554
            Klass* k = cp->klass_at(i, CHECK);
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
          break;
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
        case JVM_CONSTANT_Long:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   559
        case JVM_CONSTANT_Double:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   560
          parsed_two_word = i + 1;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   561
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   562
        case JVM_CONSTANT_ClassIndex:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   563
        case JVM_CONSTANT_StringIndex:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   564
        case JVM_CONSTANT_String:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   565
        case JVM_CONSTANT_UnresolvedClassInError:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   566
        case JVM_CONSTANT_Fieldref:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   567
        case JVM_CONSTANT_Methodref:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   568
        case JVM_CONSTANT_InterfaceMethodref:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   569
        case JVM_CONSTANT_NameAndType:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   570
        case JVM_CONSTANT_Utf8:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   571
        case JVM_CONSTANT_Integer:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   572
        case JVM_CONSTANT_Float:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   573
          if (tag != cp->tag_at(i).value()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   574
            report_error("tag mismatch: wrong class files?");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   575
            return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   576
          }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   577
          break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   578
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   579
        case JVM_CONSTANT_Class:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   580
          if (tag == JVM_CONSTANT_Class) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   581
          } else if (tag == JVM_CONSTANT_UnresolvedClass) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   582
            tty->print_cr("Warning: entry was unresolved in the replay data");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   583
          } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   584
            report_error("Unexpected tag");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   585
            return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   586
          }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   587
          break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   588
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   589
        case 0:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   590
          if (parsed_two_word == i) continue;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   591
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   592
        default:
17121
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 17000
diff changeset
   593
          fatal(err_msg_res("Unexpected tag: %d", cp->tag_at(i).value()));
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   594
          break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   595
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   596
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
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   599
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   600
  // 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
   601
  // 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
   602
  // static fields but it's impossible to properly rerun the static
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   603
  // initiailizer.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   604
  void process_staticfield(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   605
    InstanceKlass* k = (InstanceKlass *)parse_klass(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   606
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   607
    if (ReplaySuppressInitializers == 0 ||
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   608
        ReplaySuppressInitializers == 2 && k->class_loader() == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   609
      return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   610
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   611
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   612
    assert(k->is_initialized(), "must be");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   613
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   614
    const char* field_name = parse_escaped_string();;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   615
    const char* field_signature = parse_string();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   616
    fieldDescriptor fd;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   617
    Symbol* name = SymbolTable::lookup(field_name, (int)strlen(field_name), CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   618
    Symbol* sig = SymbolTable::lookup(field_signature, (int)strlen(field_signature), CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   619
    if (!k->find_local_field(name, sig, &fd) ||
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   620
        !fd.is_static() ||
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   621
        fd.has_initial_value()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   622
      report_error(field_name);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   623
      return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   624
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   625
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   626
    oop java_mirror = k->java_mirror();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   627
    if (field_signature[0] == '[') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   628
      int length = parse_int("array length");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   629
      oop value = NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   630
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   631
      if (field_signature[1] == '[') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   632
        // multi dimensional array
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   633
        ArrayKlass* kelem = (ArrayKlass *)parse_klass(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   634
        int rank = 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   635
        while (field_signature[rank] == '[') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   636
          rank++;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   637
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   638
        int* dims = NEW_RESOURCE_ARRAY(int, rank);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   639
        dims[0] = length;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   640
        for (int i = 1; i < rank; i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   641
          dims[i] = 1; // These aren't relevant to the compiler
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   642
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   643
        value = kelem->multi_allocate(rank, dims, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   644
      } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   645
        if (strcmp(field_signature, "[B") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   646
          value = oopFactory::new_byteArray(length, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   647
        } else if (strcmp(field_signature, "[Z") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   648
          value = oopFactory::new_boolArray(length, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   649
        } else if (strcmp(field_signature, "[C") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   650
          value = oopFactory::new_charArray(length, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   651
        } else if (strcmp(field_signature, "[S") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   652
          value = oopFactory::new_shortArray(length, CHECK);
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
          value = oopFactory::new_singleArray(length, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   655
        } else if (strcmp(field_signature, "[D") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   656
          value = oopFactory::new_doubleArray(length, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   657
        } else if (strcmp(field_signature, "[I") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   658
          value = oopFactory::new_intArray(length, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   659
        } else if (strcmp(field_signature, "[J") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   660
          value = oopFactory::new_longArray(length, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   661
        } else if (field_signature[0] == '[' && field_signature[1] == 'L') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   662
          KlassHandle kelem = resolve_klass(field_signature + 1, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   663
          value = oopFactory::new_objArray(kelem(), length, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   664
        } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   665
          report_error("unhandled array staticfield");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   666
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   667
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   668
      java_mirror->obj_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   669
    } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   670
      const char* string_value = parse_escaped_string();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   671
      if (strcmp(field_signature, "I") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   672
        int value = atoi(string_value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   673
        java_mirror->int_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   674
      } else if (strcmp(field_signature, "B") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   675
        int value = atoi(string_value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   676
        java_mirror->byte_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   677
      } else if (strcmp(field_signature, "C") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   678
        int value = atoi(string_value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   679
        java_mirror->char_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   680
      } else if (strcmp(field_signature, "S") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   681
        int value = atoi(string_value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   682
        java_mirror->short_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   683
      } else if (strcmp(field_signature, "Z") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   684
        int value = atol(string_value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   685
        java_mirror->bool_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   686
      } else if (strcmp(field_signature, "J") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   687
        jlong value;
15228
e92acc84ade3 7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents: 14588
diff changeset
   688
        if (sscanf(string_value, JLONG_FORMAT, &value) != 1) {
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   689
          fprintf(stderr, "Error parsing long: %s\n", string_value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   690
          return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   691
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   692
        java_mirror->long_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   693
      } else if (strcmp(field_signature, "F") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   694
        float value = atof(string_value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   695
        java_mirror->float_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   696
      } else if (strcmp(field_signature, "D") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   697
        double value = atof(string_value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   698
        java_mirror->double_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   699
      } else if (strcmp(field_signature, "Ljava/lang/String;") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   700
        Handle value = java_lang_String::create_from_str(string_value, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   701
        java_mirror->obj_field_put(fd.offset(), value());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   702
      } else if (field_signature[0] == 'L') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   703
        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
   704
        KlassHandle kelem = resolve_klass(field_signature, CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   705
        oop value = ((InstanceKlass*)kelem())->allocate_instance(CHECK);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   706
        java_mirror->obj_field_put(fd.offset(), value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   707
      } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   708
        report_error("unhandled staticfield");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   709
      }
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   713
#if INCLUDE_JVMTI
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   714
  void process_JvmtiExport(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   715
    const char* field = parse_string();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   716
    bool value = parse_int("JvmtiExport flag") != 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   717
    if (strcmp(field, "can_access_local_variables") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   718
      JvmtiExport::set_can_access_local_variables(value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   719
    } else if (strcmp(field, "can_hotswap_or_post_breakpoint") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   720
      JvmtiExport::set_can_hotswap_or_post_breakpoint(value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   721
    } else if (strcmp(field, "can_post_on_exceptions") == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   722
      JvmtiExport::set_can_post_on_exceptions(value);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   723
    } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   724
      report_error("Unrecognized JvmtiExport directive");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   725
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   726
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   727
#endif // INCLUDE_JVMTI
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   728
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   729
  // Create and initialize a record for a ciMethod
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   730
  ciMethodRecord* new_ciMethod(Method* method) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   731
    ciMethodRecord* rec = NEW_RESOURCE_OBJ(ciMethodRecord);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   732
    rec->klass =  method->method_holder()->name()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   733
    rec->method = method->name()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   734
    rec->signature = method->signature()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   735
    ci_method_records.append(rec);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   736
    return rec;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   739
  // Lookup data for a ciMethod
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   740
  ciMethodRecord* find_ciMethodRecord(Method* method) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   741
    const char* klass_name =  method->method_holder()->name()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   742
    const char* method_name = method->name()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   743
    const char* signature = method->signature()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   744
    for (int i = 0; i < ci_method_records.length(); i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   745
      ciMethodRecord* rec = ci_method_records.at(i);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   746
      if (strcmp(rec->klass, klass_name) == 0 &&
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   747
          strcmp(rec->method, method_name) == 0 &&
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   748
          strcmp(rec->signature, signature) == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   749
        return rec;
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
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   752
    return NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   753
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   754
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   755
  // Create and initialize a record for a ciMethodData
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   756
  ciMethodDataRecord* new_ciMethodData(Method* method) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   757
    ciMethodDataRecord* rec = NEW_RESOURCE_OBJ(ciMethodDataRecord);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   758
    rec->klass =  method->method_holder()->name()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   759
    rec->method = method->name()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   760
    rec->signature = method->signature()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   761
    ci_method_data_records.append(rec);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   762
    return rec;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   763
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   764
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   765
  // Lookup data for a ciMethodData
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   766
  ciMethodDataRecord* find_ciMethodDataRecord(Method* method) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   767
    const char* klass_name =  method->method_holder()->name()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   768
    const char* method_name = method->name()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   769
    const char* signature = method->signature()->as_utf8();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   770
    for (int i = 0; i < ci_method_data_records.length(); i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   771
      ciMethodDataRecord* rec = ci_method_data_records.at(i);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   772
      if (strcmp(rec->klass, klass_name) == 0 &&
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   773
          strcmp(rec->method, method_name) == 0 &&
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   774
          strcmp(rec->signature, signature) == 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   775
        return rec;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   776
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   777
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   778
    return NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   779
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   780
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   781
  const char* error_message() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   782
    return _error_message;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   783
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   784
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   785
  void reset() {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   786
    _error_message = NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   787
    ci_method_records.clear();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   788
    ci_method_data_records.clear();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   789
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   790
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   791
  // 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
   792
  // in place.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   793
  static void unescape_string(char* value) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   794
    char* from = value;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   795
    char* to = value;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   796
    while (*from != '\0') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   797
      if (*from != '\\') {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   798
        *from++ = *to++;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   799
      } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   800
        switch (from[1]) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   801
          case 'u': {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   802
            from += 2;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   803
            jchar value=0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   804
            for (int i=0; i<4; i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   805
              char c = *from++;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   806
              switch (c) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   807
                case '0': case '1': case '2': case '3': case '4':
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   808
                case '5': case '6': case '7': case '8': case '9':
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   809
                  value = (value << 4) + c - '0';
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   810
                  break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   811
                case 'a': case 'b': case 'c':
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   812
                case 'd': case 'e': case 'f':
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   813
                  value = (value << 4) + 10 + c - 'a';
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   814
                  break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   815
                case 'A': case 'B': case 'C':
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   816
                case 'D': case 'E': case 'F':
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   817
                  value = (value << 4) + 10 + c - 'A';
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   818
                  break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   819
                default:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   820
                  ShouldNotReachHere();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   821
              }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   822
            }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   823
            UNICODE::convert_to_utf8(&value, 1, to);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   824
            to++;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   825
            break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   826
          }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   827
          case 't': *to++ = '\t'; from += 2; break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   828
          case 'n': *to++ = '\n'; from += 2; break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   829
          case 'r': *to++ = '\r'; from += 2; break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   830
          case 'f': *to++ = '\f'; from += 2; break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   831
          default:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   832
            ShouldNotReachHere();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   833
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   834
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   835
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   836
    *from = *to;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   837
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   838
};
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
void ciReplay::replay(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   841
  int exit_code = replay_impl(THREAD);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   842
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   843
  Threads::destroy_vm();
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
  vm_exit(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
int ciReplay::replay_impl(TRAPS) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   849
  HandleMark hm;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   850
  ResourceMark rm;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   851
  // Make sure we don't run with background compilation
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   852
  BackgroundCompilation = false;
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
  if (ReplaySuppressInitializers > 2) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   855
    // ReplaySuppressInitializers > 2 means that we want to allow
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   856
    // normal VM bootstrap but once we get into the replay itself
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   857
    // don't allow any intializers to be run.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   858
    ReplaySuppressInitializers = 1;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   859
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   860
17121
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 17000
diff changeset
   861
  if (FLAG_IS_DEFAULT(ReplayDataFile)) {
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 17000
diff changeset
   862
    tty->print_cr("ERROR: no compiler replay data file specified (use -XX:ReplayDataFile=replay_pid12345.txt).");
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 17000
diff changeset
   863
    return 1;
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 17000
diff changeset
   864
  }
e40a97c700d9 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 17000
diff changeset
   865
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   866
  // Load and parse the replay data
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   867
  CompileReplay rp(ReplayDataFile, THREAD);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   868
  int exit_code = 0;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   869
  if (rp.can_replay()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   870
    rp.process(THREAD);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   871
  } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   872
    exit_code = 1;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   873
    return exit_code;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   874
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   875
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   876
  if (HAS_PENDING_EXCEPTION) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   877
    oop throwable = PENDING_EXCEPTION;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   878
    CLEAR_PENDING_EXCEPTION;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   879
    java_lang_Throwable::print(throwable, tty);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   880
    tty->cr();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   881
    java_lang_Throwable::print_stack_trace(throwable, tty);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   882
    tty->cr();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   883
    exit_code = 2;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   884
  }
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
  if (rp.had_error()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   887
    tty->print_cr("Failed on %s", rp.error_message());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   888
    exit_code = 1;
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
  return exit_code;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   894
void ciReplay::initialize(ciMethodData* m) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   895
  if (replay_state == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   896
    return;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   899
  ASSERT_IN_VM;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   900
  ResourceMark rm;
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
  Method* method = m->get_MethodData()->method();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   903
  ciMethodDataRecord* rec = replay_state->find_ciMethodDataRecord(method);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   904
  if (rec == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   905
    // This indicates some mismatch with the original environment and
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   906
    // the replay environment though it's not always enough to
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   907
    // interfere with reproducing a bug
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   908
    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
   909
    method->print_name(tty);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   910
    tty->cr();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   911
  } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   912
    m->_state = rec->state;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   913
    m->_current_mileage = rec->current_mileage;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   914
    if (rec->data_length != 0) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   915
      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
   916
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   917
      // Write the correct ciObjects back into the profile data
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   918
      ciEnv* env = ciEnv::current();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   919
      for (int i = 0; i < rec->oops_length; i++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   920
        KlassHandle *h = (KlassHandle *)rec->oops_handles[i];
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   921
        *(ciMetadata**)(rec->data + rec->oops_offsets[i]) =
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   922
          env->get_metadata((*h)());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   923
      }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   924
      // Copy the updated profile data into place as intptr_ts
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   925
#ifdef _LP64
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   926
      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
   927
#else
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   928
      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
   929
#endif
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   932
    // copy in the original header
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   933
    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
   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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   937
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   938
bool ciReplay::should_not_inline(ciMethod* method) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   939
  if (replay_state == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   940
    return false;
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
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   943
  VM_ENTRY_MARK;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   944
  // ciMethod without a record shouldn't be inlined.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   945
  return replay_state->find_ciMethodRecord(method->get_Method()) == NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   946
}
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   947
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   948
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   949
void ciReplay::initialize(ciMethod* m) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   950
  if (replay_state == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   951
    return;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   952
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   953
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   954
  ASSERT_IN_VM;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   955
  ResourceMark rm;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   956
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   957
  Method* method = m->get_Method();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   958
  ciMethodRecord* rec = replay_state->find_ciMethodRecord(method);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   959
  if (rec == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   960
    // This indicates some mismatch with the original environment and
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   961
    // the replay environment though it's not always enough to
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   962
    // interfere with reproducing a bug
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   963
    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
   964
    method->print_name(tty);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   965
    tty->cr();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   966
  } else {
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 15483
diff changeset
   967
    EXCEPTION_CONTEXT;
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 15483
diff changeset
   968
    MethodCounters* mcs = method->method_counters();
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   969
    // m->_instructions_size = rec->instructions_size;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   970
    m->_instructions_size = -1;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   971
    m->_interpreter_invocation_count = rec->interpreter_invocation_count;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   972
    m->_interpreter_throwout_count = rec->interpreter_throwout_count;
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 15483
diff changeset
   973
    if (mcs == NULL) {
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 15483
diff changeset
   974
      mcs = Method::build_method_counters(method, CHECK_AND_CLEAR);
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 15483
diff changeset
   975
    }
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 15483
diff changeset
   976
    mcs->invocation_counter()->_counter = rec->invocation_counter;
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 15483
diff changeset
   977
    mcs->backedge_counter()->_counter = rec->backedge_counter;
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   978
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   979
}
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   980
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   981
bool ciReplay::is_loaded(Method* method) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   982
  if (replay_state == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   983
    return true;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   984
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   985
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   986
  ASSERT_IN_VM;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   987
  ResourceMark rm;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   988
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   989
  ciMethodRecord* rec = replay_state->find_ciMethodRecord(method);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   990
  return rec != NULL;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents:
diff changeset
   991
}
14588
8ec26d2d9339 8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents: 14477
diff changeset
   992
#endif // PRODUCT