38 CompilerDirectives* DirectivesParser::pop_tmp() {
39 if (_tmp_top == NULL) {
40 return NULL;
41 }
42 CompilerDirectives* tmp = _tmp_top;
43 _tmp_top = _tmp_top->next();
44 tmp->set_next(NULL);
45 _tmp_depth--;
46 return tmp;
47 }
48
49 void DirectivesParser::clean_tmp() {
50 CompilerDirectives* tmp = pop_tmp();
51 while (tmp != NULL) {
52 delete tmp;
53 tmp = pop_tmp();
54 }
55 assert(_tmp_depth == 0, "Consistency");
56 }
57
58 bool DirectivesParser::parse_string(const char* text, outputStream* st) {
59 DirectivesParser cd(text, st);
60 if (cd.valid()) {
61 return cd.install_directives();
62 } else {
63 cd.clean_tmp();
64 st->flush();
65 st->print_cr("Parsing of compiler directives failed");
66 return false;
67 }
68 }
69
70 bool DirectivesParser::has_file() {
71 return CompilerDirectivesFile != NULL;
72 }
73
74 bool DirectivesParser::parse_from_flag() {
75 return parse_from_file(CompilerDirectivesFile, tty);
76 }
77
78 bool DirectivesParser::parse_from_file(const char* filename, outputStream* st) {
79 assert(filename != NULL, "Test before calling this");
80 if (!parse_from_file_inner(filename, st)) {
81 st->print_cr("Could not load file: %s", filename);
82 return false;
83 }
84 return true;
85 }
86
87 bool DirectivesParser::parse_from_file_inner(const char* filename, outputStream* stream) {
88 struct stat st;
89 ResourceMark rm;
90 if (os::stat(filename, &st) == 0) {
91 // found file, open it
92 int file_handle = os::open(filename, 0, 0);
93 if (file_handle != -1) {
94 // read contents into resource array
95 char* buffer = NEW_RESOURCE_ARRAY(char, st.st_size+1);
96 size_t num_read = os::read(file_handle, (char*) buffer, st.st_size);
97 buffer[num_read] = '\0';
98 // close file
99 os::close(file_handle);
100 return parse_string(buffer, stream);
101 }
102 }
103 return false;
104 }
105
106 bool DirectivesParser::install_directives() {
107 // Check limit
108 if (!DirectivesStack::check_capacity(_tmp_depth, _st)) {
109 clean_tmp();
110 return false;
111 }
112
113 // Pop from internal temporary stack and push to compileBroker.
114 CompilerDirectives* tmp = pop_tmp();
115 int i = 0;
116 while (tmp != NULL) {
117 i++;
118 DirectivesStack::push(tmp);
119 tmp = pop_tmp();
120 }
121 if (i == 0) {
122 _st->print_cr("No directives in file");
123 return false;
124 } else {
125 _st->print_cr("%i compiler directives added", i);
126 if (CompilerDirectivesPrint) {
127 // Print entire directives stack after new has been pushed.
128 DirectivesStack::print(_st);
129 }
130 return true;
131 }
132 }
133
134 DirectivesParser::DirectivesParser(const char* text, outputStream* st)
135 : JSON(text, false, st), depth(0), current_directive(NULL), current_directiveset(NULL), _tmp_top(NULL), _tmp_depth(0) {
136 #ifndef PRODUCT
137 memset(stack, 0, MAX_DEPTH * sizeof(stack[0]));
138 #endif
139 parse();
140 }
141
142 DirectivesParser::~DirectivesParser() {
143 assert(_tmp_top == NULL, "Consistency");
144 assert(_tmp_depth == 0, "Consistency");
145 }
146
147 const DirectivesParser::key DirectivesParser::keys[] = {
148 // name, keytype, allow_array, allowed_mask, set_function
149 { "c1", type_c1, 0, mask(type_directives), NULL, UnknownFlagType },
150 { "c2", type_c2, 0, mask(type_directives), NULL, UnknownFlagType },
|
38 CompilerDirectives* DirectivesParser::pop_tmp() {
39 if (_tmp_top == NULL) {
40 return NULL;
41 }
42 CompilerDirectives* tmp = _tmp_top;
43 _tmp_top = _tmp_top->next();
44 tmp->set_next(NULL);
45 _tmp_depth--;
46 return tmp;
47 }
48
49 void DirectivesParser::clean_tmp() {
50 CompilerDirectives* tmp = pop_tmp();
51 while (tmp != NULL) {
52 delete tmp;
53 tmp = pop_tmp();
54 }
55 assert(_tmp_depth == 0, "Consistency");
56 }
57
58 int DirectivesParser::parse_string(const char* text, outputStream* st) {
59 DirectivesParser cd(text, st);
60 if (cd.valid()) {
61 return cd.install_directives();
62 } else {
63 cd.clean_tmp();
64 st->flush();
65 st->print_cr("Parsing of compiler directives failed");
66 return 0;
67 }
68 }
69
70 bool DirectivesParser::has_file() {
71 return CompilerDirectivesFile != NULL;
72 }
73
74 bool DirectivesParser::parse_from_flag() {
75 return parse_from_file(CompilerDirectivesFile, tty);
76 }
77
78 bool DirectivesParser::parse_from_file(const char* filename, outputStream* st) {
79 assert(filename != NULL, "Test before calling this");
80 if (!parse_from_file_inner(filename, st)) {
81 st->print_cr("Could not load file: %s", filename);
82 return false;
83 }
84 return true;
85 }
86
87 bool DirectivesParser::parse_from_file_inner(const char* filename, outputStream* stream) {
88 struct stat st;
89 ResourceMark rm;
90 if (os::stat(filename, &st) == 0) {
91 // found file, open it
92 int file_handle = os::open(filename, 0, 0);
93 if (file_handle != -1) {
94 // read contents into resource array
95 char* buffer = NEW_RESOURCE_ARRAY(char, st.st_size+1);
96 size_t num_read = os::read(file_handle, (char*) buffer, st.st_size);
97 buffer[num_read] = '\0';
98 // close file
99 os::close(file_handle);
100 return parse_string(buffer, stream);
101 }
102 }
103 return false;
104 }
105
106 int DirectivesParser::install_directives() {
107 // Check limit
108 if (!DirectivesStack::check_capacity(_tmp_depth, _st)) {
109 clean_tmp();
110 return 0;
111 }
112
113 // Pop from internal temporary stack and push to compileBroker.
114 CompilerDirectives* tmp = pop_tmp();
115 int i = 0;
116 while (tmp != NULL) {
117 i++;
118 DirectivesStack::push(tmp);
119 tmp = pop_tmp();
120 }
121 if (i == 0) {
122 _st->print_cr("No directives in file");
123 return 0;
124 } else {
125 _st->print_cr("%i compiler directives added", i);
126 if (CompilerDirectivesPrint) {
127 // Print entire directives stack after new has been pushed.
128 DirectivesStack::print(_st);
129 }
130 return i;
131 }
132 }
133
134 DirectivesParser::DirectivesParser(const char* text, outputStream* st)
135 : JSON(text, false, st), depth(0), current_directive(NULL), current_directiveset(NULL), _tmp_top(NULL), _tmp_depth(0) {
136 #ifndef PRODUCT
137 memset(stack, 0, MAX_DEPTH * sizeof(stack[0]));
138 #endif
139 parse();
140 }
141
142 DirectivesParser::~DirectivesParser() {
143 assert(_tmp_top == NULL, "Consistency");
144 assert(_tmp_depth == 0, "Consistency");
145 }
146
147 const DirectivesParser::key DirectivesParser::keys[] = {
148 // name, keytype, allow_array, allowed_mask, set_function
149 { "c1", type_c1, 0, mask(type_directives), NULL, UnknownFlagType },
150 { "c2", type_c2, 0, mask(type_directives), NULL, UnknownFlagType },
|