< prev index next >

src/hotspot/share/prims/wbtestmethods/parserTests.cpp

Print this page

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

132       if (isarg) {
133         parser->add_dcmd_argument(argument);
134       } else {
135         parser->add_dcmd_option(argument);
136       }
137    }
138 }
139 
140 /*
141  * Will Fill in a java object array with alternating names of parsed command line options and
142  * the value that has been parsed for it:
143  * { name, value, name, value ... }
144  * This can then be checked from java.
145  */
146 WB_ENTRY(jobjectArray, WB_ParseCommandLine(JNIEnv* env, jobject o, jstring j_cmdline, jchar j_delim, jobjectArray arguments))
147   ResourceMark rm;
148   DCmdParser parser;
149 
150   const char* c_cmdline = java_lang_String::as_utf8_string(JNIHandles::resolve(j_cmdline));
151   const char c_delim = (char)(j_delim & 0xff);
152   objArrayOop argumentArray = objArrayOop(JNIHandles::resolve_non_null(arguments));
153   objArrayHandle argumentArray_ah(THREAD, argumentArray);
154 
155   int length = argumentArray_ah->length();
156 
157   for (int i = 0; i < length; i++) {
158     oop argument_oop = argumentArray_ah->obj_at(i);
159     fill_in_parser(&parser, argument_oop);
160   }
161 
162   CmdLine cmdline(c_cmdline, strlen(c_cmdline), true);
163   parser.parse(&cmdline,c_delim,CHECK_NULL);
164 
165   Klass* k = vmClasses::Object_klass();
166   objArrayOop returnvalue_array = oopFactory::new_objArray(k, parser.num_arguments() * 2, CHECK_NULL);
167   objArrayHandle returnvalue_array_ah(THREAD, returnvalue_array);
168 
169   GrowableArray<const char *>*parsedArgNames = parser.argument_name_array();
170   GenDCmdArgument* arglist = parser.arguments_list();
171 
172   for (int i = 0; i < parser.num_arguments(); i++) {
173     oop parsedName = java_lang_String::create_oop_from_str(parsedArgNames->at(i), CHECK_NULL);

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

132       if (isarg) {
133         parser->add_dcmd_argument(argument);
134       } else {
135         parser->add_dcmd_option(argument);
136       }
137    }
138 }
139 
140 /*
141  * Will Fill in a java object array with alternating names of parsed command line options and
142  * the value that has been parsed for it:
143  * { name, value, name, value ... }
144  * This can then be checked from java.
145  */
146 WB_ENTRY(jobjectArray, WB_ParseCommandLine(JNIEnv* env, jobject o, jstring j_cmdline, jchar j_delim, jobjectArray arguments))
147   ResourceMark rm;
148   DCmdParser parser;
149 
150   const char* c_cmdline = java_lang_String::as_utf8_string(JNIHandles::resolve(j_cmdline));
151   const char c_delim = (char)(j_delim & 0xff);
152   refArrayOop argumentArray = refArrayOop(JNIHandles::resolve_non_null(arguments));
153   refArrayHandle argumentArray_ah(THREAD, argumentArray);
154 
155   int length = argumentArray_ah->length();
156 
157   for (int i = 0; i < length; i++) {
158     oop argument_oop = argumentArray_ah->obj_at(i);
159     fill_in_parser(&parser, argument_oop);
160   }
161 
162   CmdLine cmdline(c_cmdline, strlen(c_cmdline), true);
163   parser.parse(&cmdline,c_delim,CHECK_NULL);
164 
165   Klass* k = vmClasses::Object_klass();
166   objArrayOop returnvalue_array = oopFactory::new_objArray(k, parser.num_arguments() * 2, CHECK_NULL);
167   objArrayHandle returnvalue_array_ah(THREAD, returnvalue_array);
168 
169   GrowableArray<const char *>*parsedArgNames = parser.argument_name_array();
170   GenDCmdArgument* arglist = parser.arguments_list();
171 
172   for (int i = 0; i < parser.num_arguments(); i++) {
173     oop parsedName = java_lang_String::create_oop_from_str(parsedArgNames->at(i), CHECK_NULL);
< prev index next >