< prev index next >

src/share/vm/compiler/directivesParser.cpp

Print this page
rev 13166 : read/write APIs in class os shall return ssize_t
   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  *


  76   return parse_from_file(CompilerDirectivesFile, tty);
  77 }
  78 
  79 bool DirectivesParser::parse_from_file(const char* filename, outputStream* st) {
  80   assert(filename != NULL, "Test before calling this");
  81   if (!parse_from_file_inner(filename, st)) {
  82     st->print_cr("Could not load file: %s", filename);
  83     return false;
  84   }
  85   return true;
  86 }
  87 
  88 bool DirectivesParser::parse_from_file_inner(const char* filename, outputStream* stream) {
  89   struct stat st;
  90   ResourceMark rm;
  91   if (os::stat(filename, &st) == 0) {
  92     // found file, open it
  93     int file_handle = os::open(filename, 0, 0);
  94     if (file_handle != -1) {
  95       // read contents into resource array
  96       char* buffer = NEW_RESOURCE_ARRAY(char, st.st_size+1);
  97       size_t num_read = os::read(file_handle, (char*) buffer, st.st_size);
  98       buffer[num_read] = '\0';
  99       // close file
 100       os::close(file_handle);
 101       return parse_string(buffer, stream) > 0;
 102     }
 103   }
 104   return false;
 105 }
 106 
 107 int DirectivesParser::install_directives() {
 108   // Check limit
 109   if (!DirectivesStack::check_capacity(_tmp_depth, _st)) {
 110     clean_tmp();
 111     return 0;
 112   }
 113 
 114   // Pop from internal temporary stack and push to compileBroker.
 115   CompilerDirectives* tmp = pop_tmp();
 116   int i = 0;
 117   while (tmp != NULL) {
 118     i++;


   1 /*
   2  * Copyright (c) 2015, 2017, 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  *


  76   return parse_from_file(CompilerDirectivesFile, tty);
  77 }
  78 
  79 bool DirectivesParser::parse_from_file(const char* filename, outputStream* st) {
  80   assert(filename != NULL, "Test before calling this");
  81   if (!parse_from_file_inner(filename, st)) {
  82     st->print_cr("Could not load file: %s", filename);
  83     return false;
  84   }
  85   return true;
  86 }
  87 
  88 bool DirectivesParser::parse_from_file_inner(const char* filename, outputStream* stream) {
  89   struct stat st;
  90   ResourceMark rm;
  91   if (os::stat(filename, &st) == 0) {
  92     // found file, open it
  93     int file_handle = os::open(filename, 0, 0);
  94     if (file_handle != -1) {
  95       // read contents into resource array
  96       char* buffer = NEW_RESOURCE_ARRAY(char, st.st_size + 1);
  97       ssize_t num_read = os::read(file_handle, (char*) buffer, st.st_size);
  98       buffer[num_read < 0 ? 0 : (size_t)num_read] = '\0';
  99       // close file
 100       os::close(file_handle);
 101       return parse_string(buffer, stream) > 0;
 102     }
 103   }
 104   return false;
 105 }
 106 
 107 int DirectivesParser::install_directives() {
 108   // Check limit
 109   if (!DirectivesStack::check_capacity(_tmp_depth, _st)) {
 110     clean_tmp();
 111     return 0;
 112   }
 113 
 114   // Pop from internal temporary stack and push to compileBroker.
 115   CompilerDirectives* tmp = pop_tmp();
 116   int i = 0;
 117   while (tmp != NULL) {
 118     i++;


< prev index next >