hotspot/src/share/vm/compiler/directivesParser.cpp
author neliasso
Wed, 16 Dec 2015 15:38:28 +0100
changeset 35129 8b93709bf4e5
parent 35105 dd35f17e611d
child 35130 223598d44a8b
permissions -rw-r--r--
8144246: adding lots of directives via jcmd may produce OOM crash Summary: Add a limit to the number of directives Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     1
/*
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     4
 *
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     8
 *
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    13
 * accompanied this code).
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    14
 *
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    18
 *
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    21
 * questions.
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    22
 *
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    23
 */
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    24
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    25
#include "precompiled.hpp"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    26
#include "compiler/compileBroker.hpp"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    27
#include "compiler/directivesParser.hpp"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    28
#include "memory/allocation.inline.hpp"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    29
#include "runtime/os.hpp"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    30
#include <string.h>
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    31
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    32
void DirectivesParser::push_tmp(CompilerDirectives* dir) {
35129
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
    33
  _tmp_depth++;
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    34
  dir->set_next(_tmp_top);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    35
  _tmp_top = dir;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    36
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    37
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    38
CompilerDirectives* DirectivesParser::pop_tmp() {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    39
  if (_tmp_top == NULL) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    40
    return NULL;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    41
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    42
  CompilerDirectives* tmp = _tmp_top;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    43
  _tmp_top = _tmp_top->next();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    44
  tmp->set_next(NULL);
35129
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
    45
  _tmp_depth--;
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    46
  return tmp;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    47
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    48
35129
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
    49
void DirectivesParser::clean_tmp() {
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
    50
  CompilerDirectives* tmp = pop_tmp();
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
    51
  while (tmp != NULL) {
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
    52
    delete tmp;
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
    53
    tmp = pop_tmp();
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
    54
  }
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
    55
  assert(_tmp_depth == 0, "Consistency");
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
    56
}
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
    57
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    58
bool DirectivesParser::parse_string(const char* text, outputStream* st) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    59
  DirectivesParser cd(text, st);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    60
  if (cd.valid()) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    61
    return cd.install_directives();
35129
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
    62
  } else {
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
    63
    cd.clean_tmp();
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
    64
    st->flush();
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
    65
    st->print_cr("Parsing of compiler directives failed");
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
    66
    return false;
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    67
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    68
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    69
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    70
bool DirectivesParser::has_file() {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    71
  return CompilerDirectivesFile != NULL;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    72
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    73
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    74
bool DirectivesParser::parse_from_flag() {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    75
  return parse_from_file(CompilerDirectivesFile, tty);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    76
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    77
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    78
bool DirectivesParser::parse_from_file(const char* filename, outputStream* st) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    79
  assert(filename != NULL, "Test before calling this");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    80
  if (!parse_from_file_inner(filename, st)) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    81
    st->print_cr("Could not load file: %s", filename);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    82
    return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    83
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    84
  return true;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    85
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    86
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    87
bool DirectivesParser::parse_from_file_inner(const char* filename, outputStream* stream) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    88
  struct stat st;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    89
  ResourceMark rm;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    90
  if (os::stat(filename, &st) == 0) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    91
    // found file, open it
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    92
    int file_handle = os::open(filename, 0, 0);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    93
    if (file_handle != -1) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    94
      // read contents into resource array
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    95
      char* buffer = NEW_RESOURCE_ARRAY(char, st.st_size+1);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    96
      size_t num_read = os::read(file_handle, (char*) buffer, st.st_size);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    97
      buffer[num_read] = '\0';
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    98
      // close file
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
    99
      os::close(file_handle);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   100
      return parse_string(buffer, stream);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   101
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   102
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   103
  return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   104
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   105
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   106
bool DirectivesParser::install_directives() {
35129
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
   107
  // Check limit
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
   108
  if (!DirectivesStack::check_capacity(_tmp_depth, _st)) {
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
   109
    clean_tmp();
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
   110
    return false;
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
   111
  }
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
   112
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   113
  // Pop from internal temporary stack and push to compileBroker.
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   114
  CompilerDirectives* tmp = pop_tmp();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   115
  int i = 0;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   116
  while (tmp != NULL) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   117
    i++;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   118
    DirectivesStack::push(tmp);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   119
    tmp = pop_tmp();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   120
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   121
  if (i == 0) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   122
    _st->print_cr("No directives in file");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   123
    return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   124
  } else {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   125
    _st->print_cr("%i compiler directives added", i);
35129
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
   126
    if (CompilerDirectivesPrint) {
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   127
      // Print entire directives stack after new has been pushed.
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   128
      DirectivesStack::print(_st);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   129
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   130
    return true;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   131
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   132
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   133
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   134
DirectivesParser::DirectivesParser(const char* text, outputStream* st)
35129
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
   135
: JSON(text, false, st), depth(0), current_directive(NULL), current_directiveset(NULL), _tmp_top(NULL), _tmp_depth(0) {
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   136
#ifndef PRODUCT
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   137
  memset(stack, 0, MAX_DEPTH * sizeof(stack[0]));
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   138
#endif
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   139
  parse();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   140
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   141
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   142
DirectivesParser::~DirectivesParser() {
35129
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
   143
  assert(_tmp_top == NULL, "Consistency");
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
   144
  assert(_tmp_depth == 0, "Consistency");
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   145
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   146
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   147
const DirectivesParser::key DirectivesParser::keys[] = {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   148
    // name, keytype, allow_array, allowed_mask, set_function
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   149
    { "c1",     type_c1,     0, mask(type_directives), NULL, UnknownFlagType },
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   150
    { "c2",     type_c2,     0, mask(type_directives), NULL, UnknownFlagType },
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   151
    { "match",  type_match,  1, mask(type_directives), NULL, UnknownFlagType },
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   152
    { "inline", type_inline, 1, mask(type_directives) | mask(type_c1) | mask(type_c2), NULL, UnknownFlagType },
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   153
    { "enable", type_enable, 1, mask(type_directives) | mask(type_c1) | mask(type_c2), NULL, UnknownFlagType },
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   154
    { "preset", type_preset, 0, mask(type_c1) | mask(type_c2), NULL, UnknownFlagType },
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   155
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   156
    // Global flags
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   157
    #define common_flag_key(name, type, dvalue, compiler) \
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   158
    { #name, type_flag, 0, mask(type_directives) | mask(type_c1) | mask(type_c2), &DirectiveSet::set_##name, type##Flag},
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   159
    compilerdirectives_common_flags(common_flag_key)
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   160
    compilerdirectives_c2_flags(common_flag_key)
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   161
    compilerdirectives_c1_flags(common_flag_key)
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   162
    #undef common_flag_key
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   163
};
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   164
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   165
const DirectivesParser::key DirectivesParser::dir_array_key = {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   166
     "top level directives array", type_dir_array, 0, 1 // Lowest bit means allow at top level
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   167
};
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   168
const DirectivesParser::key DirectivesParser::dir_key = {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   169
   "top level directive", type_directives, 0, mask(type_dir_array) | 1 // Lowest bit means allow at top level
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   170
};
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   171
const DirectivesParser::key DirectivesParser::value_array_key = {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   172
   "value array", type_value_array, 0, UINT_MAX // Allow all, checked by allow_array on other keys, not by allowed_mask from this key
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   173
};
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   174
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   175
const DirectivesParser::key* DirectivesParser::lookup_key(const char* str, size_t len) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   176
  for (size_t i = 0; i < (sizeof(keys) / sizeof(keys[0])); i++) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   177
    if (strncasecmp(keys[i].name, str, len) == 0) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   178
      return &keys[i];
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   179
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   180
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   181
  return NULL;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   182
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   183
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   184
uint DirectivesParser::mask(keytype kt) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   185
  return 1 << (kt + 1);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   186
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   187
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   188
bool DirectivesParser::push_key(const char* str, size_t len) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   189
  bool result = true;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   190
  const key* k = lookup_key(str, len);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   191
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   192
  if (k == NULL) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   193
    // os::strdup
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   194
    char* s = NEW_C_HEAP_ARRAY(char, len + 1, mtCompiler);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   195
    strncpy(s, str, len);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   196
    s[len] = '\0';
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   197
    error(KEY_ERROR, "No such key: '%s'.", s);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   198
    FREE_C_HEAP_ARRAY(char, s);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   199
    return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   200
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   201
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   202
  return push_key(k);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   203
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   204
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   205
bool DirectivesParser::push_key(const key* k) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   206
  assert(k->allowedmask != 0, "not allowed anywhere?");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   207
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   208
  // Exceeding the stack should not be possible with a valid compiler directive,
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   209
  // and an invalid should abort before this happens
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   210
  assert(depth < MAX_DEPTH, "exceeded stack depth");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   211
  if (depth >= MAX_DEPTH) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   212
    error(INTERNAL_ERROR, "Stack depth exceeded.");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   213
    return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   214
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   215
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   216
  assert(stack[depth] == NULL, "element not nulled, something is wrong");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   217
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   218
  if (depth == 0 && !(k->allowedmask & 1)) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   219
    error(KEY_ERROR, "Key '%s' not allowed at top level.", k->name);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   220
    return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   221
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   222
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   223
  if (depth > 0) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   224
    const key* prev = stack[depth - 1];
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   225
    if (!(k->allowedmask & mask(prev->type))) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   226
      error(KEY_ERROR, "Key '%s' not allowed after '%s' key.", k->name, prev->name);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   227
      return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   228
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   229
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   230
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   231
  stack[depth] = k;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   232
  depth++;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   233
  return true;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   234
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   235
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   236
const DirectivesParser::key* DirectivesParser::current_key() {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   237
  assert(depth > 0, "getting key from empty stack");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   238
  if (depth == 0) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   239
    return NULL;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   240
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   241
  return stack[depth - 1];
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   242
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   243
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   244
const DirectivesParser::key* DirectivesParser::pop_key() {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   245
  assert(depth > 0, "popping empty stack");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   246
  if (depth == 0) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   247
    error(INTERNAL_ERROR, "Popping empty stack.");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   248
    return NULL;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   249
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   250
  depth--;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   251
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   252
  const key* k = stack[depth];
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   253
#ifndef PRODUCT
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   254
  stack[depth] = NULL;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   255
#endif
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   256
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   257
  return k;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   258
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   259
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   260
bool DirectivesParser::set_option_flag(JSON_TYPE t, JSON_VAL* v, const key* option_key, DirectiveSet* set) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   261
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   262
  void (DirectiveSet::*test)(void *args);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   263
  test = option_key->set;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   264
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   265
  switch (t) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   266
    case JSON_TRUE:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   267
      if (option_key->flag_type != boolFlag) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   268
        error(VALUE_ERROR, "Cannot use bool value for an %s flag", flag_type_names[option_key->flag_type]);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   269
        return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   270
      } else {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   271
        bool val = true;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   272
        (set->*test)((void *)&val);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   273
      }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   274
      break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   275
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   276
    case JSON_FALSE:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   277
      if (option_key->flag_type != boolFlag) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   278
        error(VALUE_ERROR, "Cannot use bool value for an %s flag", flag_type_names[option_key->flag_type]);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   279
        return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   280
      } else {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   281
        bool val = false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   282
        (set->*test)((void *)&val);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   283
      }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   284
      break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   285
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   286
    case JSON_NUMBER_INT:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   287
      if (option_key->flag_type != intxFlag) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   288
        if (option_key->flag_type == doubleFlag) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   289
          double dval = (double)v->int_value;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   290
          (set->*test)((void *)&dval);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   291
          break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   292
        }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   293
        error(VALUE_ERROR, "Cannot use int value for an %s flag", flag_type_names[option_key->flag_type]);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   294
        return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   295
      } else {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   296
        intx ival = v->int_value;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   297
        (set->*test)((void *)&ival);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   298
      }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   299
      break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   300
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   301
    case JSON_NUMBER_FLOAT:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   302
      if (option_key->flag_type != doubleFlag) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   303
        error(VALUE_ERROR, "Cannot use double value for an %s flag", flag_type_names[option_key->flag_type]);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   304
        return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   305
      } else {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   306
        double dval = v->double_value;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   307
        (set->*test)((void *)&dval);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   308
      }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   309
      break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   310
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   311
    case JSON_STRING:
33480
e4cef6796874 8138651: -XX:DisableIntrinsic matches intrinsics overly eagerly
zmajo
parents: 33451
diff changeset
   312
      if (option_key->flag_type != ccstrFlag && option_key->flag_type != ccstrlistFlag) {
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   313
        error(VALUE_ERROR, "Cannot use string value for a %s flag", flag_type_names[option_key->flag_type]);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   314
        return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   315
      } else {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   316
        char* s = NEW_C_HEAP_ARRAY(char, v->str.length+1,  mtCompiler);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   317
        strncpy(s, v->str.start, v->str.length + 1);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   318
        s[v->str.length] = '\0';
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   319
        (set->*test)((void *)&s);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   320
      }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   321
      break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   322
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   323
    default:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   324
      assert(0, "Should not reach here.");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   325
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   326
  return true;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   327
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   328
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   329
bool DirectivesParser::set_option(JSON_TYPE t, JSON_VAL* v) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   330
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   331
  const key* option_key = pop_key();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   332
  const key* enclosing_key = current_key();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   333
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   334
  if (option_key->type == value_array_key.type) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   335
    // Multi value array, we are really setting the value
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   336
    // for the key one step further up.
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   337
    option_key = pop_key();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   338
    enclosing_key = current_key();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   339
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   340
    // Repush option_key and multi value marker, since
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   341
    // we need to keep them until all multi values are set.
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   342
    push_key(option_key);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   343
    push_key(&value_array_key);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   344
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   345
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   346
  switch (option_key->type) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   347
  case type_flag:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   348
  {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   349
    if (current_directiveset == NULL) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   350
      assert(depth == 2, "Must not have active directive set");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   351
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   352
      if (!set_option_flag(t, v, option_key, current_directive->_c1_store)) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   353
        return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   354
      }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   355
      if(!set_option_flag(t, v, option_key, current_directive->_c2_store)) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   356
        return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   357
      }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   358
    } else {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   359
      assert(depth > 2, "Must have active current directive set");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   360
      if (!set_option_flag(t, v, option_key, current_directiveset)) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   361
        return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   362
      }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   363
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   364
    break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   365
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   366
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   367
  case type_match:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   368
    if (t != JSON_STRING) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   369
      error(VALUE_ERROR, "Key of type %s needs a value of type string", option_key->name);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   370
      return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   371
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   372
    if (enclosing_key->type != type_directives) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   373
      error(SYNTAX_ERROR, "Match keyword can only exist inside a directive");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   374
      return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   375
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   376
    {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   377
      char* s = NEW_C_HEAP_ARRAY(char, v->str.length + 1, mtCompiler);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   378
      strncpy(s, v->str.start, v->str.length);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   379
      s[v->str.length] = '\0';
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   380
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   381
      const char* error_msg = NULL;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   382
      if (!current_directive->add_match(s, error_msg)) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   383
        assert (error_msg != NULL, "Must have valid error message");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   384
        error(VALUE_ERROR, "Method pattern error: %s", error_msg);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   385
      }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   386
      FREE_C_HEAP_ARRAY(char, s);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   387
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   388
    break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   389
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   390
  case type_inline:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   391
    if (t != JSON_STRING) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   392
      error(VALUE_ERROR, "Key of type %s needs a value of type string", option_key->name);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   393
      return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   394
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   395
    {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   396
      //char* s = strndup(v->str.start, v->str.length);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   397
      char* s = NEW_C_HEAP_ARRAY(char, v->str.length + 1, mtCompiler);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   398
      strncpy(s, v->str.start, v->str.length);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   399
      s[v->str.length] = '\0';
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   400
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   401
      const char* error_msg = NULL;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   402
      if (current_directiveset == NULL) {
35105
dd35f17e611d 8144601: Premature assert in directive inline parsing
neliasso
parents: 33480
diff changeset
   403
        if (current_directive->_c1_store->parse_and_add_inline(s, error_msg)) {
dd35f17e611d 8144601: Premature assert in directive inline parsing
neliasso
parents: 33480
diff changeset
   404
          if (!current_directive->_c2_store->parse_and_add_inline(s, error_msg)) {
dd35f17e611d 8144601: Premature assert in directive inline parsing
neliasso
parents: 33480
diff changeset
   405
            assert (error_msg != NULL, "Must have valid error message");
dd35f17e611d 8144601: Premature assert in directive inline parsing
neliasso
parents: 33480
diff changeset
   406
            error(VALUE_ERROR, "Method pattern error: %s", error_msg);
dd35f17e611d 8144601: Premature assert in directive inline parsing
neliasso
parents: 33480
diff changeset
   407
          }
dd35f17e611d 8144601: Premature assert in directive inline parsing
neliasso
parents: 33480
diff changeset
   408
        } else {
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   409
          assert (error_msg != NULL, "Must have valid error message");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   410
          error(VALUE_ERROR, "Method pattern error: %s", error_msg);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   411
        }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   412
      } else {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   413
        if (!current_directiveset->parse_and_add_inline(s, error_msg)) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   414
          assert (error_msg != NULL, "Must have valid error message");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   415
          error(VALUE_ERROR, "Method pattern error: %s", error_msg);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   416
        }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   417
      }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   418
      FREE_C_HEAP_ARRAY(char, s);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   419
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   420
    break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   421
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   422
  case type_c1:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   423
    current_directiveset = current_directive->_c1_store;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   424
    if (t != JSON_TRUE && t != JSON_FALSE) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   425
      error(VALUE_ERROR, "Key of type %s needs a true or false value", option_key->name);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   426
      return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   427
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   428
    break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   429
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   430
  case type_c2:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   431
    current_directiveset = current_directive->_c2_store;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   432
    if (t != JSON_TRUE && t != JSON_FALSE) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   433
      error(VALUE_ERROR, "Key of type %s needs a true or false value", option_key->name);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   434
      return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   435
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   436
    break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   437
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   438
  case type_enable:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   439
    switch (enclosing_key->type) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   440
    case type_c1:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   441
    case type_c2:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   442
    {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   443
      if (t != JSON_TRUE && t != JSON_FALSE) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   444
        error(VALUE_ERROR, "Key of type %s enclosed in a %s key needs a true or false value", option_key->name, enclosing_key->name);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   445
        return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   446
      }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   447
      int val = (t == JSON_TRUE);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   448
      current_directiveset->set_Enable(&val);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   449
      break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   450
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   452
    case type_directives:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   453
      error(VALUE_ERROR, "Enable keyword not available for generic directive");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   454
      return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   455
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   456
    default:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   457
      error(INTERNAL_ERROR, "Unexpected enclosing type for key %s: %s", option_key->name, enclosing_key->name);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   458
      ShouldNotReachHere();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   459
      return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   460
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   461
    break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   462
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   463
  default:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   464
    break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   465
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   466
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   467
  return true;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   468
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   469
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   470
bool DirectivesParser::callback(JSON_TYPE t, JSON_VAL* v, uint rlimit) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   471
  const key* k;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   472
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   473
  if (depth == 0) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   474
    switch (t) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   475
      case JSON_ARRAY_BEGIN:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   476
        return push_key(&dir_array_key);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   477
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   478
      case JSON_OBJECT_BEGIN:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   479
        // push synthetic dir_array
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   480
        push_key(&dir_array_key);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   481
        assert(depth == 1, "Make sure the stack are aligned with the directives");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   482
        break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   483
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   484
      default:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   485
        error(SYNTAX_ERROR, "DirectivesParser can only start with an array containing directive objects, or one single directive.");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   486
        return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   487
      }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   488
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   489
  if (depth == 1) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   490
    switch (t) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   491
      case JSON_OBJECT_BEGIN:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   492
        // Parsing a new directive.
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   493
        current_directive = new CompilerDirectives();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   494
        return push_key(&dir_key);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   495
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   496
      case JSON_ARRAY_END:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   497
        k = pop_key();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   498
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   499
        if (k->type != type_dir_array) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   500
          error(SYNTAX_ERROR, "Expected end of directives array");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   501
          return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   502
        }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   503
        return true;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   504
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   505
    default:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   506
      error(SYNTAX_ERROR, "DirectivesParser can only start with an array containing directive objects, or one single directive.");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   507
      return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   508
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   509
  } else {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   510
    switch (t) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   511
    case JSON_OBJECT_BEGIN:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   512
      k = current_key();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   513
      switch (k->type) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   514
      case type_c1:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   515
        current_directiveset = current_directive->_c1_store;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   516
        return true;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   517
      case type_c2:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   518
        current_directiveset = current_directive->_c2_store;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   519
        return true;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   520
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   521
      case type_dir_array:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   522
        return push_key(&dir_key);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   523
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   524
      default:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   525
        error(SYNTAX_ERROR, "The key '%s' does not allow an object to follow.", k->name);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   526
        return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   527
      }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   528
      return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   529
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   530
    case JSON_OBJECT_END:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   531
      k = pop_key();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   532
      switch (k->type) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   533
      case type_c1:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   534
      case type_c2:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   535
        // This is how we now if options apply to a single or both directive sets
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   536
        current_directiveset = NULL;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   537
        break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   538
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   539
      case type_directives:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   540
        // Check, finish and push to stack!
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   541
        if (current_directive->match() == NULL) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   542
          error(INTERNAL_ERROR, "Directive missing required match.");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   543
          return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   544
        }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   545
        current_directive->finalize();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   546
        push_tmp(current_directive);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   547
        current_directive = NULL;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   548
        break;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   549
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   550
      default:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   551
        error(INTERNAL_ERROR, "Object end with wrong key type on stack: %s.", k->name);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   552
        ShouldNotReachHere();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   553
        return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   554
      }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   555
      return true;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   556
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   557
    case JSON_ARRAY_BEGIN:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   558
      k = current_key();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   559
      if (!(k->allow_array_value)) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   560
        if (k->type == type_dir_array) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   561
          error(SYNTAX_ERROR, "Array not allowed inside top level array, expected directive object.");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   562
        } else {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   563
          error(VALUE_ERROR, "The key '%s' does not allow an array of values.", k->name);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   564
        }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   565
        return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   566
      }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   567
      return push_key(&value_array_key);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   568
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   569
    case JSON_ARRAY_END:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   570
      k = pop_key(); // Pop multi value marker
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   571
      assert(k->type == value_array_key.type, "array end for level != 0 should terminate multi value");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   572
      k = pop_key(); // Pop key for option that was set
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   573
      return true;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   574
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   575
    case JSON_KEY:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   576
      return push_key(v->str.start, v->str.length);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   577
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   578
    case JSON_STRING:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   579
    case JSON_NUMBER_INT:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   580
    case JSON_NUMBER_FLOAT:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   581
    case JSON_TRUE:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   582
    case JSON_FALSE:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   583
    case JSON_NULL:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   584
      return set_option(t, v);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   585
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   586
    default:
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   587
      error(INTERNAL_ERROR, "Unknown JSON type: %d.", t);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   588
      ShouldNotReachHere();
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   589
      return false;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   590
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   591
  }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   592
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   593
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   594
#ifndef PRODUCT
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   595
void DirectivesParser::test(const char* text, bool should_pass) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   596
  DirectivesParser cd(text, tty);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   597
  if (should_pass) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   598
    assert(cd.valid() == true, "failed on a valid DirectivesParser string");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   599
    if (VerboseInternalVMTests) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   600
      tty->print("-- DirectivesParser test passed as expected --\n");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   601
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   602
  } else {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   603
    assert(cd.valid() == false, "succeeded on an invalid DirectivesParser string");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   604
    if (VerboseInternalVMTests) {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   605
      tty->print("-- DirectivesParser test failed as expected --\n");
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   606
    }
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   607
  }
35129
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 35105
diff changeset
   608
  cd.clean_tmp();
33451
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   609
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   610
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   611
bool DirectivesParser::test() {
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   612
  DirectivesParser::test("{}", false);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   613
  DirectivesParser::test("[]", true);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   614
  DirectivesParser::test("[{}]", false);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   615
  DirectivesParser::test("[{},{}]", false);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   616
  DirectivesParser::test("{},{}", false);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   617
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   618
  DirectivesParser::test(
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   619
    "[" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   620
    "  {" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   621
    "    match: \"foo/bar.*\"," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   622
    "    inline : \"+java/util.*\"," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   623
    "    PrintAssembly: true," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   624
    "    BreakAtExecute: true," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   625
    "  }" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   626
    "]" "\n", true);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   627
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   628
  DirectivesParser::test(
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   629
    "[" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   630
    "  [" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   631
    "    {" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   632
    "      match: \"foo/bar.*\"," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   633
    "      inline : \"+java/util.*\"," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   634
    "      PrintAssembly: true," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   635
    "      BreakAtExecute: true," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   636
    "    }" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   637
    "  ]" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   638
    "]" "\n", false);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   639
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   640
  /*DirectivesParser::test(
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   641
    "[" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   642
    "  {" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   643
    "    match: \"foo/bar.*\"," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   644
    "    c1: {"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   645
    "      PrintIntrinsics: false," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   646
    "    }" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   647
    "  }" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   648
    "]" "\n", false);*/
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   649
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   650
  DirectivesParser::test(
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   651
    "[" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   652
    "  {" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   653
    "    match: \"foo/bar.*\"," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   654
    "    c2: {" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   655
    "      PrintInlining: false," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   656
    "    }" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   657
    "  }" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   658
    "]" "\n", true);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   659
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   660
  DirectivesParser::test(
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   661
    "[" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   662
    "  {" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   663
    "    match: \"foo/bar.*\"," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   664
    "    PrintInlining: [" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   665
    "      true," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   666
    "      false" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   667
    "    ]," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   668
    "  }" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   669
    "]" "\n", false);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   670
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   671
  DirectivesParser::test(
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   672
    "[" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   673
    "  {"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   674
    "    // pattern to match against class+method+signature" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   675
    "    // leading and trailing wildcard (*) allowed" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   676
    "    match: \"foo/bar.*\"," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   677
    "" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   678
    "    // override defaults for specified compiler" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   679
    "    // we may differentiate between levels too. TBD." "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   680
    "    c1:  {" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   681
    "      //override c1 presets " "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   682
    "      DumpReplay: false," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   683
    "      BreakAtCompile: true," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   684
    "    }," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   685
    "" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   686
    "    c2: {" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   687
    "        // control inlining of method" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   688
    "        // + force inline, - dont inline" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   689
    "        inline : \"+java/util.*\"," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   690
    "        PrintInlining: true," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   691
    "    }," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   692
    "" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   693
    "    // directives outside a specific preset applies to all compilers" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   694
    "    inline : [ \"+java/util.*\", \"-com/sun.*\"]," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   695
    "    BreakAtExecute: true," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   696
    "    Log: true," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   697
    "  }," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   698
    "  {" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   699
    "    // matching several patterns require an array" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   700
    "    match: [\"baz.*\",\"frob.*\"]," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   701
    "" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   702
    "    // applies to all compilers" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   703
    "    // + force inline, - dont inline" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   704
    "    inline : [ \"+java/util.*\", \"-com/sun.*\" ]," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   705
    "    PrintInlining: true," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   706
    "" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   707
    "    // force matching compiles to be blocking/syncronous" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   708
    "    PrintNMethods: true" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   709
    "  }," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   710
    "]" "\n", true);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   711
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   712
  // Test max stack depth
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   713
    DirectivesParser::test(
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   714
      "[" "\n"             // depth 1: type_dir_array
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   715
      "  {" "\n"           // depth 2: type_directives
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   716
      "    match: \"*.*\"," // match required
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   717
      "    c1:" "\n"       // depth 3: type_c1
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   718
      "    {" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   719
      "      inline:" "\n" // depth 4: type_inline
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   720
      "      [" "\n"       // depth 5: type_value_array
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   721
      "        \"foo\"," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   722
      "        \"bar\"," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   723
      "      ]" "\n"       // depth 3: pop type_value_array and type_inline keys
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   724
      "    }" "\n"         // depth 2: pop type_c1 key
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   725
      "  }" "\n"           // depth 1: pop type_directives key
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   726
      "]" "\n", true);     // depth 0: pop type_dir_array key
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   727
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   728
    // Test max stack depth
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   729
    DirectivesParser::test(
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   730
      "[{c1:{c1:{c1:{c1:{c1:{c1:{c1:{}}}}}}}}]", false);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   731
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   732
  DirectivesParser::test(
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   733
    "[" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   734
    "  {" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   735
    "    c1: true," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   736
    "    c2: true," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   737
    "    match: true," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   738
    "    inline: true," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   739
    "    enable: true," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   740
    "    c1: {" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   741
    "      preset: true," "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   742
    "    }" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   743
    "  }" "\n"
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   744
    "]" "\n", false);
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   745
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   746
  return true;
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   747
}
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   748
0712796e4039 8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
diff changeset
   749
#endif