Path: blob/master/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/ClassRef.java
6004 views
/*******************************************************************************1* Copyright (c) 2004, 2021 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/21package com.ibm.oti.VMCPTool;2223import java.io.PrintWriter;2425import org.w3c.dom.Element;2627public class ClassRef extends PrimaryItem implements Constants {2829private static final class Alias extends PrimaryItem.Alias {30final J9UTF8 name;3132Alias(VersionRange[] versions, String[] flags, J9UTF8 name) {33super(versions, flags);34this.name = name;35}3637protected boolean isIncluded() {38return true;39}4041void writeSecondaryItems(ConstantPoolStream ds) {42ds.writeSecondaryItem(name);43}4445void write(ConstantPoolStream ds) {46ds.alignTo(4);47ds.markClass();48ds.writeInt(ds.getOffset(name) - ds.getOffset());4950Main.JCLRuntimeFlag flag;51if (flags.length == 0) {52flag = Main.getRuntimeFlag("default");53} else {54if (flags.length > 1) {55System.err.println("Error: tool cannot handle complex flag expressions");56System.exit(-1);57}58flag = Main.getRuntimeFlag(flags[0]);59}60ds.writeInt(flag.value);61}62}6364public ClassRef(Element e) {65super(e, CLASSALIAS, new Alias.Factory() {66public PrimaryItem.Alias alias(Element e, PrimaryItem.Alias proto) {67Alias p = (Alias) proto;68return new Alias(ClassRef.versions(e, p), ClassRef.flags(e, p),69new J9UTF8(ClassRef.attribute(e, "name", p != null ? p.name.data : "")));70}71});72}7374protected String cMacroName() {75char[] buf = ((Alias) primary).name.data.toCharArray();76int j = 0;7778for (int i = 0; i < buf.length; i++) {79if (buf[i] != '/' && buf[i] != '$') {80buf[j++] = buf[i];81}82}83return new String(buf, 0, j).toUpperCase();84}8586public void writeMacros(ConstantPool pool, PrintWriter out) {87super.writeMacros(pool, out);8889String macroName = cMacroName();90out.println("#define J9VM" + macroName + "(vm) J9VMCONSTANTPOOL_CLASS_AT(vm, J9VMCONSTANTPOOL_" + macroName + ")");91out.println("#define J9VM" + macroName + "_OR_NULL(vm) (J9VMCONSTANTPOOL_CLASSREF_AT(vm, J9VMCONSTANTPOOL_" + macroName + ")->value)");92}9394public String getClassName() {95return ((Alias) primary).name.data;96}9798public String commentText() {99return "ClassRef[" + getClassName() + "]";100}101102}103104105