Skip to content

Commit 6c97cf7

Browse files
authored
Merge pull request #40 from microsphere-projects/dev
Release v0.0.9
2 parents cae6eac + 07ca432 commit 6c97cf7

13 files changed

Lines changed: 187 additions & 23 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.microsphere.annotation;
18+
19+
import io.microsphere.util.Version;
20+
21+
import java.lang.annotation.Documented;
22+
import java.lang.annotation.Retention;
23+
import java.lang.annotation.RetentionPolicy;
24+
import java.lang.annotation.Target;
25+
26+
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
27+
import static java.lang.annotation.ElementType.CONSTRUCTOR;
28+
import static java.lang.annotation.ElementType.FIELD;
29+
import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
30+
import static java.lang.annotation.ElementType.METHOD;
31+
import static java.lang.annotation.ElementType.PACKAGE;
32+
import static java.lang.annotation.ElementType.PARAMETER;
33+
import static java.lang.annotation.ElementType.TYPE;
34+
import static java.lang.annotation.ElementType.TYPE_PARAMETER;
35+
import static java.lang.annotation.ElementType.TYPE_USE;
36+
37+
/**
38+
* The annotation that indicates the API is introduced in the first time.
39+
*
40+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy<a/>
41+
* @see Version
42+
* @see Experimental
43+
* @since 1.0.0
44+
*/
45+
@Retention(RetentionPolicy.RUNTIME)
46+
@Target({
47+
TYPE,
48+
FIELD,
49+
METHOD,
50+
PARAMETER,
51+
CONSTRUCTOR,
52+
LOCAL_VARIABLE,
53+
ANNOTATION_TYPE,
54+
PACKAGE,
55+
TYPE_PARAMETER,
56+
TYPE_USE
57+
})
58+
@Documented
59+
public @interface Since {
60+
61+
/**
62+
* @return The module name, e.g. <code>microsphere-core</code>
63+
*/
64+
String module() default "";
65+
66+
/**
67+
* @return The version value of the API, e.g. <code>1.0.0</code>
68+
* @see Version
69+
*/
70+
String value();
71+
}

microsphere-java-core/src/main/java/io/microsphere/classloading/AbstractURLClassPathHandle.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ public final boolean removeURL(ClassLoader classLoader, URL url) {
104104
URL base = getFieldValue(loader, getBaseField());
105105
String basePath_ = resolveBasePath(base);
106106
if (Objects.equals(basePath_, basePath)) {
107-
logger.debug("Remove the Class-Path URL:{}", url);
107+
if (logger.isTraceEnabled()) {
108+
logger.trace("Remove the Class-Path URL:{}", url);
109+
}
108110
iterator.remove();
109111
removed = true;
110112
break;

microsphere-java-core/src/main/java/io/microsphere/classloading/ArtifactDetector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ protected Set<URL> getClassPathURLs(boolean includedJdkLibraries) {
7979
if (!includedJdkLibraries) {
8080
removeJdkClassPathURLs(classPathURLs);
8181
}
82-
if (logger.isDebugEnabled()) {
82+
if (logger.isTraceEnabled()) {
8383
StringJoiner stringJoiner = new StringJoiner(System.lineSeparator());
8484
for (URL classPathURL : classPathURLs) {
8585
stringJoiner.add(classPathURL.toString());
8686
}
87-
logger.debug("ClassLoader[{}] covers the URLs[expected: {}, actual: {}], class-path : {}",
87+
logger.trace("ClassLoader[{}] covers the URLs[expected: {}, actual: {}], class-path : {}",
8888
classLoader, urls.size(), classPathURLs.size(), stringJoiner);
8989
}
9090
return classPathURLs;

microsphere-java-core/src/main/java/io/microsphere/classloading/ManifestArtifactResolver.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ private String resolveArtifactId(Attributes attributes, URL artifactResourceURL,
124124
}
125125

126126
if (artifactId == null) {
127-
if (logger.isDebugEnabled()) {
128-
logger.debug("The artifactId can't be resolved from the {} of artifact[resource: {}] : {}",
127+
if (logger.isTraceEnabled()) {
128+
logger.trace("The artifactId can't be resolved from the {} of artifact[resource: {}] : {}",
129129
artifactResourceURL.getPath(),
130130
MANIFEST_RESOURCE_PATH,
131131
attributes.entrySet()
@@ -172,9 +172,11 @@ private String resolveVersion(Attributes attributes, String artifactId, URL arti
172172
}
173173

174174
if (version == null) {
175-
logger.debug("The version can't be found in the {} of artifact[Path: {}]", MANIFEST_RESOURCE_PATH,
176-
artifactResourceURL.getPath()
177-
);
175+
if (logger.isTraceEnabled()) {
176+
logger.trace("The version can't be found in the {} of artifact[Path: {}]", MANIFEST_RESOURCE_PATH,
177+
artifactResourceURL.getPath()
178+
);
179+
}
178180
}
179181

180182
return version;

microsphere-java-core/src/main/java/io/microsphere/classloading/MavenArtifactResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ protected void doResolve(Collection<Artifact> artifactSet, URLClassLoader urlCla
5757
Artifact artifact = resolveArtifactMetaInfoInMavenPomProperties(mavenPomPropertiesResource);
5858
if (artifact != null) {
5959
artifactSet.add(artifact);
60-
if (logger.isDebugEnabled()) {
61-
logger.debug("The artifact was resolved from the the Maven pom.properties[resource : {}] : {}", mavenPomPropertiesResource, artifact);
60+
if (logger.isTraceEnabled()) {
61+
logger.trace("The artifact was resolved from the the Maven pom.properties[resource : {}] : {}", mavenPomPropertiesResource, artifact);
6262
}
6363
}
6464
}

microsphere-java-core/src/main/java/io/microsphere/classloading/WindowsRedefinedClassLoader.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ private Class<?> loadRedefinedClass(RedefinedClassMetadata metadata, boolean res
7777
File[] files = packageDirectory.listFiles(file -> classFileName.equals(file.getName()));
7878
if (files.length == 1) {
7979
File classFile = files[0];
80-
logger.debug("Class[name: {}] file [name: {}] found in Package directory [path: {}], about to execute ClassLoader.defineClass",
81-
className, classFileName, packageDirectory.getAbsolutePath());
80+
if (logger.isTraceEnabled()) {
81+
logger.trace("Class[name: {}] file [name: {}] found in Package directory [path: {}], about to execute ClassLoader.defineClass",
82+
className, classFileName, packageDirectory.getAbsolutePath());
83+
}
8284
try (FileInputStream inputStream = new FileInputStream(classFile)) {
8385
byte[] byteCodes = toByteArray(inputStream);
8486
result = super.defineClass(className, byteCodes, 0, byteCodes.length);
@@ -122,8 +124,10 @@ private RedefinedClassMetadata resolveRedefinedClassMetadata(String className, C
122124
while (packageResources.hasMoreElements()) {
123125
URL packageResource = packageResources.nextElement();
124126
if (!"file".equalsIgnoreCase(packageResource.getProtocol())) {
125-
logger.debug("Class [name: {}] is located in a non-file system directory [path: {}], RedefinedClassMetadata does not need to be processed!",
126-
className, packageResource);
127+
if (logger.isTraceEnabled()) {
128+
logger.trace("Class [name: {}] is located in a non-file system directory [path: {}], RedefinedClassMetadata does not need to be processed!",
129+
className, packageResource);
130+
}
127131
continue;
128132
}
129133
File packageDirectory = new File(packageResource.getPath());

microsphere-java-core/src/main/java/io/microsphere/reflect/MethodUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ public static Method findDeclaredMethod(Class<?> targetClass, String methodName,
254254
}
255255

256256
if (method == null) {
257-
if (logger.isDebugEnabled()) {
258-
logger.debug("The declared method was not found in the target class[name : '{}'] by name['{}'] and parameter types['{}']",
257+
if (logger.isTraceEnabled()) {
258+
logger.trace("The declared method was not found in the target class[name : '{}'] by name['{}'] and parameter types['{}']",
259259
targetClass, methodName, Arrays.toString(parameterTypes));
260260
}
261261
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.microsphere.invoke;
18+
19+
import org.openjdk.jmh.annotations.Benchmark;
20+
import org.openjdk.jmh.annotations.BenchmarkMode;
21+
import org.openjdk.jmh.annotations.Fork;
22+
import org.openjdk.jmh.annotations.Measurement;
23+
import org.openjdk.jmh.annotations.Mode;
24+
import org.openjdk.jmh.annotations.OutputTimeUnit;
25+
import org.openjdk.jmh.annotations.Scope;
26+
import org.openjdk.jmh.annotations.State;
27+
import org.openjdk.jmh.annotations.Warmup;
28+
29+
import java.lang.invoke.MethodHandle;
30+
import java.lang.reflect.Method;
31+
import java.util.concurrent.TimeUnit;
32+
33+
import static io.microsphere.invoke.MethodHandleUtils.findVirtual;
34+
import static io.microsphere.reflect.MethodUtils.findMethod;
35+
36+
/**
37+
* The benchmark of {@link MethodHandleUtils}
38+
*
39+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy<a/>
40+
* @see MethodHandleUtils
41+
* @since 1.0.0
42+
*/
43+
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
44+
@Measurement(iterations = 20, time = 1, timeUnit = TimeUnit.SECONDS)
45+
@Fork(3)
46+
@BenchmarkMode(Mode.AverageTime)
47+
@OutputTimeUnit(TimeUnit.NANOSECONDS)
48+
@State(Scope.Thread)
49+
public class MethodHandleUtilsBenchmark {
50+
51+
private static final MethodHandle staticMethodHandle = findVirtual(MethodHandleUtilsBenchmark.class, "echo");
52+
53+
private static final Method method = findMethod(MethodHandleUtilsBenchmark.class, "echo");
54+
55+
private final MethodHandle methodHandle = findVirtual(MethodHandleUtilsBenchmark.class, "echo");
56+
57+
static {
58+
method.setAccessible(true);
59+
}
60+
61+
@Benchmark
62+
public void directAccess() {
63+
this.echo();
64+
}
65+
66+
@Benchmark
67+
public void invokeMethod() throws Throwable {
68+
method.invoke(this);
69+
}
70+
71+
@Benchmark
72+
public void invokeExactMethodHandle() throws Throwable {
73+
invokeExact(methodHandle);
74+
}
75+
76+
@Benchmark
77+
public void invokeExactStaticMethodHandle() throws Throwable {
78+
invokeExact(staticMethodHandle);
79+
}
80+
81+
private void invokeExact(MethodHandle methodHandle) throws Throwable {
82+
methodHandle.invokeExact(this);
83+
}
84+
85+
private void echo() {
86+
}
87+
}

microsphere-java-core/src/test/java/io/microsphere/reflect/ConstructorDefinitionTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.microsphere.reflect;
22

33
import io.microsphere.lang.Deprecation;
4-
import io.microsphere.util.ClassUtils;
54
import io.microsphere.util.Version;
65
import org.junit.jupiter.api.Test;
76

microsphere-java-core/src/test/java/io/microsphere/reflect/FieldDefinitionTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import static io.microsphere.lang.DeprecationTest.DEPRECATION;
2424
import static io.microsphere.lang.DeprecationTest.SINCE;
25-
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
2625
import static org.junit.jupiter.api.Assertions.assertEquals;
2726
import static org.junit.jupiter.api.Assertions.assertNotNull;
2827
import static org.junit.jupiter.api.Assertions.assertNull;

0 commit comments

Comments
 (0)