src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Code.java
changeset 59285 7799a51dbe30
parent 54568 b2ed96c35687
equal deleted inserted replaced
59284:88502b1cf76f 59285:7799a51dbe30
     1 /*
     1 /*
     2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    48 import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_MethodType;
    48 import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_MethodType;
    49 import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Methodref;
    49 import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_Methodref;
    50 import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_String;
    50 import static com.sun.tools.javac.jvm.ClassFile.CONSTANT_String;
    51 import static com.sun.tools.javac.jvm.UninitializedType.*;
    51 import static com.sun.tools.javac.jvm.UninitializedType.*;
    52 import static com.sun.tools.javac.jvm.ClassWriter.StackMapTableFrame;
    52 import static com.sun.tools.javac.jvm.ClassWriter.StackMapTableFrame;
       
    53 import java.util.Arrays;
    53 
    54 
    54 /** An internal structure that corresponds to the code attribute of
    55 /** An internal structure that corresponds to the code attribute of
    55  *  methods in a classfile. The class also provides some utility operations to
    56  *  methods in a classfile. The class also provides some utility operations to
    56  *  generate bytecode instructions.
    57  *  generate bytecode instructions.
    57  *
    58  *
  2073             char length = (char)(curCP() - v.lastRange().start_pc);
  2074             char length = (char)(curCP() - v.lastRange().start_pc);
  2074             if (length < Character.MAX_VALUE) {
  2075             if (length < Character.MAX_VALUE) {
  2075                 lvar[adr] = v.dup();
  2076                 lvar[adr] = v.dup();
  2076                 v.closeRange(length);
  2077                 v.closeRange(length);
  2077                 putVar(v);
  2078                 putVar(v);
       
  2079                 fillLocalVarPosition(v);
  2078             } else {
  2080             } else {
  2079                 v.removeLastRange();
  2081                 v.removeLastRange();
  2080             }
  2082             }
  2081         }
  2083         }
  2082     }
  2084     }
  2104     }
  2106     }
  2105 
  2107 
  2106     private void fillLocalVarPosition(LocalVar lv) {
  2108     private void fillLocalVarPosition(LocalVar lv) {
  2107         if (lv == null || lv.sym == null || lv.sym.isExceptionParameter()|| !lv.sym.hasTypeAnnotations())
  2109         if (lv == null || lv.sym == null || lv.sym.isExceptionParameter()|| !lv.sym.hasTypeAnnotations())
  2108             return;
  2110             return;
  2109         LocalVar.Range widestRange = lv.getWidestRange();
  2111         LocalVar.Range[] validRanges = lv.aliveRanges.stream().filter(r -> r.closed() && r.length > 0).toArray(s -> new LocalVar.Range[s]);
       
  2112         if (validRanges.length == 0)
       
  2113             return ;
       
  2114         int[] lvarOffset = Arrays.stream(validRanges).mapToInt(r -> r.start_pc).toArray();
       
  2115         int[] lvarLength = Arrays.stream(validRanges).mapToInt(r -> r.length).toArray();
       
  2116         int[] lvarIndex = Arrays.stream(validRanges).mapToInt(r -> lv.reg).toArray();
  2110         for (Attribute.TypeCompound ta : lv.sym.getRawTypeAttributes()) {
  2117         for (Attribute.TypeCompound ta : lv.sym.getRawTypeAttributes()) {
  2111             TypeAnnotationPosition p = ta.position;
  2118             TypeAnnotationPosition p = ta.position;
  2112             if (widestRange.closed() && widestRange.length > 0) {
  2119             p.lvarOffset = appendArray(p.lvarOffset, lvarOffset);
  2113                 p.lvarOffset = new int[] { (int)widestRange.start_pc };
  2120             p.lvarLength = appendArray(p.lvarLength, lvarLength);
  2114                 p.lvarLength = new int[] { (int)widestRange.length };
  2121             p.lvarIndex = appendArray(p.lvarIndex, lvarIndex);
  2115                 p.lvarIndex = new int[] { (int)lv.reg };
  2122             p.isValidOffset = true;
  2116                 p.isValidOffset = true;
  2123         }
  2117             } else {
  2124     }
  2118                 p.isValidOffset = false;
  2125 
  2119             }
  2126     private int[] appendArray(int[] source, int[] append) {
  2120         }
  2127         if (source == null || source.length == 0) return append;
       
  2128 
       
  2129         int[] result = new int[source.length + append.length];
       
  2130 
       
  2131         System.arraycopy(source, 0, result, 0, source.length);
       
  2132         System.arraycopy(append, 0, result, source.length, append.length);
       
  2133         return result;
  2121     }
  2134     }
  2122 
  2135 
  2123     // Method to be called after compressCatchTable to
  2136     // Method to be called after compressCatchTable to
  2124     // fill in the exception table index for type
  2137     // fill in the exception table index for type
  2125     // annotations on exception parameters.
  2138     // annotations on exception parameters.