src/hotspot/share/compiler/directivesParser.hpp
changeset 47216 71c04702a3d5
parent 42617 9ac2fe949f27
child 52290 db83eceba962
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 /*
       
     2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  *
       
    23  */
       
    24 
       
    25 #ifndef SHARE_VM_COMPILER_DIRECTIVESPARSER_HPP
       
    26 #define SHARE_VM_COMPILER_DIRECTIVESPARSER_HPP
       
    27 
       
    28 #include "utilities/json.hpp"
       
    29 #include "compiler/compilerDirectives.hpp"
       
    30 
       
    31 enum FlagType {
       
    32   boolFlag,
       
    33   intxFlag,
       
    34   uintxFlag,
       
    35   doubleFlag,
       
    36   ccstrFlag,
       
    37   ccstrlistFlag,
       
    38   UnknownFlagType
       
    39 };
       
    40 
       
    41 static const char* flag_type_names[] = {
       
    42     "bool",
       
    43     "int",
       
    44     "uint",
       
    45     "double",
       
    46     "string",
       
    47     "string list",
       
    48     "unknown"
       
    49 };
       
    50 
       
    51 class DirectivesParser : public JSON {
       
    52 public:
       
    53   static bool has_file();
       
    54   static bool parse_from_flag();
       
    55   static bool parse_from_file(const char* filename, outputStream* st);
       
    56   static int  parse_string(const char* string, outputStream* st);
       
    57   int install_directives();
       
    58 
       
    59 private:
       
    60   DirectivesParser(const char* text, outputStream* st, bool silent);
       
    61   ~DirectivesParser();
       
    62 
       
    63   bool callback(JSON_TYPE t, JSON_VAL* v, uint level);
       
    64   static bool parse_from_file_inner(const char* filename, outputStream* st);
       
    65 
       
    66   // types of "keys". i.e recognized <key>:<value> pairs in our JSON syntax
       
    67   typedef enum {
       
    68      type_c1,
       
    69      type_c2,
       
    70      type_enable,
       
    71      type_preset,
       
    72      type_match,
       
    73      type_inline,
       
    74 
       
    75      // After here, there is no correlation between
       
    76      // keytype and keys array
       
    77      //type_strategy,
       
    78      type_flag,
       
    79      //type_dir,
       
    80 
       
    81      // Synthetic.
       
    82      type_dir_array,
       
    83      type_directives,
       
    84      type_value_array
       
    85   } keytype;
       
    86 
       
    87   // name, type, dtd info and maybe a setter
       
    88   // this is how we map key-values
       
    89   typedef struct {
       
    90      const char *name;
       
    91      keytype     type;
       
    92      uint    allow_array_value : 1;
       
    93      uint    allowedmask;
       
    94      void (DirectiveSet::*set)(void* arg);
       
    95      FlagType flag_type;
       
    96   } key;
       
    97 
       
    98   // Array with valid keys for the directive file
       
    99   static const key keys[];
       
   100   // Marker for outermost moosewings/array
       
   101   static const key dir_array_key;
       
   102   // Marker for a directives set (these are "implicit" objects, as in not named)
       
   103   static const key dir_key;
       
   104   // Marker for a multi value
       
   105   static const key value_array_key;
       
   106 
       
   107   // A compiler directive shouldn't be able to use more than 5 stack slots.
       
   108   // Example of max stack usage:
       
   109   // depth 1: type_dir_array  [
       
   110   // depth 2: type_directives   {
       
   111   // depth 3: type_c1             c1: {
       
   112   // depth 4: type_inline           inline:
       
   113   // depth 5: type_value_array      [ ...
       
   114   static const uint MAX_DEPTH = 5;
       
   115   const key* stack[MAX_DEPTH];
       
   116   uint depth;
       
   117 
       
   118   bool push_key(const char* str, size_t len);
       
   119   bool push_key(const key* k);
       
   120   const key* current_key();
       
   121   const key* pop_key();
       
   122   static const key* lookup_key(const char* s, size_t len);
       
   123 
       
   124   bool set_option(JSON_TYPE t, JSON_VAL* v);
       
   125   bool set_option_flag(JSON_TYPE t, JSON_VAL* v, const key* option_key, DirectiveSet* set);
       
   126 
       
   127   CompilerDirectives* current_directive;
       
   128   DirectiveSet*       current_directiveset;
       
   129 
       
   130   void push_tmp(CompilerDirectives* dir);
       
   131   void clean_tmp();
       
   132   CompilerDirectives* pop_tmp();
       
   133   CompilerDirectives* _tmp_top; // temporary storage for dirs while parsing
       
   134   int _tmp_depth;               // Number of directives that has been parsed but not installed.
       
   135 
       
   136   static uint mask(keytype kt);
       
   137 
       
   138 #ifndef PRODUCT
       
   139   static void test(const char* json, bool valid);
       
   140 public:
       
   141   static void test();
       
   142 #endif
       
   143 };
       
   144 
       
   145 #endif // SHARE_VM_COMPILER_DIRECTIVESPARSER_HPP