Skip to content

Commit

Permalink
Revert optimization removal (eclipse-ee4j#1352)
Browse files Browse the repository at this point in the history
* Revert optimization removal javaee/jaxb-v2#1157

  * Keep optimization for Java versions older then 9 with multi-release jar
  * Add noOptimization flag for possible compatibility issues

Signed-off-by: Daniel Kec <daniel.kec@oracle.com>
  • Loading branch information
danielkec authored and lukasj committed Nov 29, 2019
1 parent dd028b2 commit 263e92e
Show file tree
Hide file tree
Showing 22 changed files with 1,299 additions and 5 deletions.
5 changes: 5 additions & 0 deletions jaxb-ri/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
</plugins>
</pluginManagement>

Expand Down
108 changes: 108 additions & 0 deletions jaxb-ri/runtime/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,80 @@

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-mr-resource</id>
<phase>prepare-package</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${mrjar.sourceDirectory}</directory>
<targetPath>META-INF/versions</targetPath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile-mr</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<compileSourceRoots>
<compileSourceRoot>${mrjar.sourceDirectory}/${upper.java.level}</compileSourceRoot>
</compileSourceRoots>
<outputDirectory>${project.build.outputDirectory}/META-INF/versions/${upper.java.level}</outputDirectory>
<source>${upper.java.level}</source>
<target>${upper.java.level}</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Implementation-Vendor>${vendor.name}</Implementation-Vendor>
<Implementation-Vendor-Id>${project.groupId}</Implementation-Vendor-Id>
<Implementation-Build-Id>${project.version} - ${scmBranch}-${buildNumber}, ${timestamp}</Implementation-Build-Id>
<Multi-Release>true</Multi-Release>
<Import-Package>
javax.activation;version=!,
*
</Import-Package>
</instructions>
</configuration>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand All @@ -90,7 +164,41 @@
--add-opens org.glassfish.jaxb.runtime/com.sun.xml.bind.v2=java.xml.bind
--add-opens org.glassfish.jaxb.runtime/com.sun.xml.bind.v2.schemagen=java.xml.bind
--add-opens org.glassfish.jaxb.runtime/com.sun.xml.bind.v2.schemagen.xmlidref=java.xml.bind
--add-opens java.base/java.lang=org.glassfish.jaxb.runtime
--add-opens java.base/java.lang.reflect=org.glassfish.jaxb.runtime
--add-opens org.glassfish.jaxb.runtime/com.sun.xml.bind.v2.runtime.reflect.opt=java.xml.bind
</argLine>
</configuration>
</plugin>

<!-- Run tests on multi-release jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<systemProperties>
<property>
<name>java.util.logging.config.file</name>
<value>logging.properties</value>
</property>
</systemProperties>
<argLine>
--add-opens java.base/java.lang=com.sun.xml.bind
--add-opens org.glassfish.jaxb.runtime/com.sun.xml.bind.v2=java.xml.bind
--add-opens org.glassfish.jaxb.runtime/com.sun.xml.bind.v2.schemagen=java.xml.bind
--add-opens org.glassfish.jaxb.runtime/com.sun.xml.bind.v2.schemagen.xmlidref=java.xml.bind
</argLine>
<includes>
<include>**/*TestMultiRelease.java</include>
</includes>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

package com.sun.xml.bind.v2.runtime.reflect.opt;

import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.sun.xml.bind.Utils;
import com.sun.xml.bind.v2.bytecode.ClassTailor;

/**
* Stub version of {@link AccessorInjector} for java versions >= 9
*
* @author Daniel Kec
*/
class AccessorInjector {

protected static final boolean noOptimize = true;

public static Class<?> prepare(
Class beanClass, String templateClassName, String newClassName, String... replacements) {
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

package com.sun.xml.bind.v2.runtime.reflect.opt;

/**
* Stub version of {@link Injector} for java versions >= 9
*
* @author Daniel Kec
*/
final class Injector {

/**
* Injects a new class into the given class loader.
*
* @return null
* if it fails to inject.
*/
static Class inject(ClassLoader cl, String className, byte[] image) {
return null;
}

/**
* Returns the already injected class, or null.
*/
static Class find(ClassLoader cl, String className) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

package com.sun.xml.bind.v2.runtime.reflect.opt;

import com.sun.xml.bind.v2.runtime.reflect.Accessor;

import java.util.logging.Logger;

import java.lang.reflect.Method;
import java.lang.reflect.Field;

import java.util.logging.Logger;

/**
* Stub version of {@link OptimizedAccessorFactory} for java versions >= 9
*
* @author Daniel Kec
*/
public abstract class OptimizedAccessorFactory {
private OptimizedAccessorFactory() {} // no instantiation please

private static final Logger logger = Logger.getLogger(OptimizedAccessorFactory.class.getName());


public static <B, V> Accessor<B, V> get(Method param1, Method param2) {
return getStub();
}

public static <B, V> Accessor<B, V> get(Field param) {
return getStub();
}

private static <B, V> Accessor<B, V> getStub(){
logger.finer("Optimization is not available since java 9");
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

package com.sun.xml.bind.v2.runtime.reflect.opt;

import com.sun.xml.bind.v2.model.runtime.RuntimePropertyInfo;
import com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor;

import java.util.logging.Logger;

/**
* Stub version of {@link OptimizedTransducedAccessorFactory} for java versions >= 9
*
* @author Daniel Kec
*/
public abstract class OptimizedTransducedAccessorFactory {
private OptimizedTransducedAccessorFactory() {} // no instantiation please

private static final Logger logger = Logger.getLogger(OptimizedTransducedAccessorFactory.class.getName());

public static final TransducedAccessor get(RuntimePropertyInfo prop) {
logger.finer("Optimization is not available since java 9");
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ public boolean useNamespace() {
return false;
}

public final boolean isDefault() {
return true;
}

public void declareNamespace(T o, XMLSerializer w) throws AccessorException {
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -332,6 +332,10 @@ public boolean useNamespace() {
return xacc.useNamespace();
}

public boolean isDefault() {
return false;
}

public void declareNamespace(BeanT bean, XMLSerializer w) throws AccessorException {
try {
xacc.declareNamespace(bean,w);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -95,6 +95,10 @@ public QName[] getTypeNames() {
return new QName[]{getTypeName()};
}

public boolean isDefault() {
return false;
}

@Override
public Class getClazz() {
return clazz;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -32,6 +32,12 @@ protected FilterTransducer(Transducer<T> core) {
this.core = core;
}

public final boolean isDefault() {
// this must be used as a decorating transducer,
// so it may never be default.
return false;
}

public boolean useNamespace() {
return core.useNamespace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand All @@ -20,6 +20,7 @@
import com.sun.istack.NotNull;
import com.sun.xml.bind.api.AccessorException;
import com.sun.xml.bind.v2.model.runtime.RuntimePropertyInfo;
import com.sun.xml.bind.v2.runtime.reflect.opt.OptimizedTransducedAccessorFactory;

import org.xml.sax.SAXException;

Expand All @@ -38,6 +39,14 @@
*/
public interface Transducer<ValueT> {

/**
* If this {@link Transducer} is the default transducer for the <code>ValueT</code>,
* this method returns true.
*
* Used exclusively by {@link OptimizedTransducedAccessorFactory#get(RuntimePropertyInfo)}
*/
boolean isDefault();

/**
* If true, this {@link Transducer} doesn't declare any namespace,
* and therefore {@link #declareNamespace(Object, XMLSerializer)} is no-op.
Expand Down
Loading

0 comments on commit 263e92e

Please sign in to comment.